c++ - can't read from the webcam -
for strange reasons, program fails read frame webcam. opens webcam though. i've searched problem , found out variety of solutions none of them worked me. code
#include <iostream> #include <cstdlib> #include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" int main() { // access default webcam cv::videocapture cap(0); // double check webcam before start reading. if ( !cap.isopened() ){ std::cerr << "cannot open webcam " << std::endl; exit (exit_failure); } cv::mat frame; cv::namedwindow("webcam",cv_window_autosize); while ( true ){ // acquire frame cap >> frame; // safety checking if ( !frame.data ){ std::cerr << "cannot acquire frame webcam " << std::endl; break; } cv::imshow("webcam", frame); if ( cv::waitkey(30) == 27){ std::cout << "esc key pressed" << std::endl; break; } } return 0; }
and window before terminating program.
i'm using windows 7 ( dell laptop ). code compiled in release mode linking against .dlls. opencv version 2.4.10. in commmand prompt
cl /ehsc main.cpp /fetest.exe /i d:\cpp_libraries\opencv_2.4.10\build\include /link /libpath:d:\cpp_libraries\opencv_2.4.10\build\x86\vc12\lib opencv_core2410.lib opencv_highgui2410.lib
i have run same code in ubuntu (dual boot alongside windows 7) , opens webcam not through highgui , got error
highgui error: v4l/v4l2: vidioc_s_crop init done opengl support available
any suggestions regarding matter. after diggings, some ppl pointed out cmake
, therefore need reinstall opencv , configure cmake
properly. there solutions problem without reinstall library if problem both ubuntu , windows ?
follow opencv documentation videocapture heure : videocapture. provides simple example video capturing in c++.
there differences code, on mat frame
inside loop.
Comments
Post a Comment