c++ - I can't capture frames from camera in OpenCV -
i trying detect eyes have problem. cannot display camera frame. problem can obvious newbie. part of code below:
here eyedetection.h
#include <opencv2/imgproc/imgproc.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/objdetect/objdetect.hpp> using namespace cv; class eyedetection { private: cascadeclassifier eye_cascade, eyepair_cascade; public: eyedetection(); void detect(); }; here eyedetection.cpp
#include "eyedetection.h" eyedetection::eyedetection() { eye_cascade.load("haarcascade_eye.xml"); eyepair_cascade.load("haarcascade_mcs_eyepair_big.xml"); } void eyedetection::detect() { videocapture webcam(1); //webcam number 1 if (eyepair_cascade.empty() || eye_cascade.empty() || !(webcam).isopened()) return; webcam.set(cv_cap_prop_frame_width, 800); webcam.set(cv_cap_prop_frame_height, 600); mat frame; while (1) { webcam >> frame; if (frame.empty()) continue; imshow("asad", frame); } } and here source.cpp(main):
#include "eyedetection.h" using namespace cv; int main(int argc, char** argv) { eyedetection e = eyedetection(); e.detect(); return 0; } it not show camera frame, shows blank gray window. problem?
- please check camera id 1. if have 1 connected camera please replace camera id 0 instead 1.
cv2.videocapture(1) cv2.videocapture(0)
- add waitkey() line add line @ end of loop
`
while (1) { webcam >> frame; if (frame.empty()) continue; imshow("asad", frame); cv2.waitkey(0) } ` maybe check waitkey() should needed you. thanks.
Comments
Post a Comment