Equipment for experiments with technical vision – web-camera Logitech HD Webcam C270

Equipment provided by the company Farnellfor which she (and personally Ryan Gibson) many thanks!

So I got my hands on a camera Logitech HD Webcam C270
Logitech HD Webcam C270
* USB 2.0 interface
* built-in microphone
* cable length – 1.5 m

Picture Options:
* Video resolution: 1280×720
* Interpolated photo resolution 3 million pixels.

OS
*Windows XP SP2/Vista/7
Supports UVC (USB Video Class – USB Device Class Definition for Video Devices),

Device ID 046d:0825 Logitech HD Webcam C270

and therefore should work without problems under Linux (even under openwrt on a D-Link DIR-320 Wi-Fi router)

The picture quality from the camera is noticeably better than from the cheaper webcams I’ve used so far (for example, distortion is almost imperceptible).
This gives hope for the possibility of more reliable and stable operation of computer vision algorithms.

Let’s see how the camera works under OpenCV through the C++ interface.

//
// тестирование видеозахвата OpenCV через интерфейс C++
//
// https://robocraft.ru
//

#include "opencv2/opencv.hpp"

int main(int argc, char* argv[])
{
	cv::VideoCapture cap(0); // откроем камеру по-умолчанию
	if(!cap.isOpened())		 // успешно?
	{
		std::cout<<"[!] Error: cant open camera!"<<std::endl;
		return -1;
	}
	cv::Mat gray;
	cv::Mat edges;
	cv::namedWindow("frame");
	cv::namedWindow("edges");
	while(1)
	{
		cv::Mat frame;
		// у VideoCapture перегружен оператор >> ,который можно использовать для считывания кадра
		cap >> frame; // получаем новый кадр
		cv::imshow("frame", frame);		// показываем картинку
		cv::cvtColor(frame, gray, CV_BGR2GRAY); // конвертируем в градации серого
		cv::GaussianBlur(gray, gray, cv::Size(7,7), 1.5, 1.5); // размытие (фильтром Гаусса)
		cv::Canny(gray, edges, 0, 30);	// детектор границ Кенни
		cv::imshow("edges", edges);		// показываем картинку
		int key = cv::waitKey(33);
		if(key == 27) //ESC
			break;
		else if(key == 13) // Enter
		{
			// сохраним кадр в файл
			cv::imwrite("frame.jpg", frame);
			cv::imwrite("edges.jpg", edges);
			std::cout<<"[i] Saved."<<std::endl;
		}

	}
	// камера будет автоматически освобождена в деструкторе VideoCapture
	return 0;
}

download source (ocv_capture.cpp)
Frame from Logitech C270
Highlighting borders on a frame with the Logitech C270

As you can see, the software part has not changed significantly and is actually a wrapper around the same C functions.

bool VideoCapture::open(int device)
{
    cap = cvCreateCameraCapture(device);
    return isOpened();
}

One of the benefits of the C++ interface is that you don’t have to worry about releasing resources, because this is done automatically in object destructors.

to be continued…

Equipment for experiments with technical vision – web-camera Logitech HD Webcam C270

Leave a Reply

Your email address will not be published.

Scroll to top