Bu yazımızda c++ kullanarak opencv de webcamdan nasıl görüntü alacağız onu anlatacağım.
#include <iostream> #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/core/core.hpp" using namespace std; using namespace cv; int main() { VideoCapture video(0); //0 dahili webcam eğer usb ile webcam bağlı ise 1,2,3 yapabilirsiniz burayı if (!video.isOpened())//eger webcam acilamazsa { cout << "Video acilamadi" << endl; } video.set(CV_CAP_PROP_POS_MSEC, 3000); //video'ya 3000 milisaniye sonra başla double fps = video.get(CV_CAP_PROP_FPS); cout << "Video fps sayisi:" << fps << endl; namedWindow("deneme", CV_WINDOW_AUTOSIZE); //deneme isimli windows penceresi oluştu while (true) //sonsuz dongu { Mat img; bool frameOkundu = video.read(img); //video'yu img'ye frame frame okuyor if (!frameOkundu) //eger okunacak frame kalmadiysa { cout << "Okunacak frame kalmadi" << endl; break; //donguden cik } imshow("deneme", img); if (waitKey(30) == 27) //27 ascii tus karsiligi ESC tusudur. 30 milisaniye ESC'ye basilirsa { cout << "Esc ile cikis yapildi" << endl; destroyWindow("deneme"); //pecere kapandı break; } } getchar(); system("Pause"); return 0; }
Bir önceki yazımız olan Arduino nedir ? başlıklı makalemizi de okumanızı öneririz.