Opencv 3.2 and Videocapture not work [closed]

asked 2017-05-03 07:35:14 -0600

GiGa.91 gravatar image

Hello to all. I'm noob whit opencv. I'm trying to use Windows 7, Opencv 3.2 and Visual Studio. I test example whit VideoCapture and .avi and it is ok. When i test VideoCapture whit cam usb it is not work. Can someone help me? the code is:

#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"

using namespace cv;
int main(int, char**)
    VideoCapture cap(0); // open the default camera
    if (!cap.isOpened())  // check if we succeeded
        return -1;

    Mat edges;
    namedWindow("edges", 1);
        Mat frame;
        cap >> frame; // get a new frame from camera
    return 0;

If I try this code the program opens the room but I see nothing (gray window)

***** VIDEOINPUT LIBRARY - 0.1995 - TFW07 *****

SETUP: Setting up device 0
SETUP: Couldn't find preview pin using SmartTee
SETUP: Default Format is set to 640x480
SETUP: trying specified format RGB24 @ 640x480
SETUP: trying format RGB24 @ 640x480
SETUP: trying format RGB32 @ 640x480
SETUP: trying format RGB555 @ 640x480
SETUP: trying format RGB565 @ 640x480
SETUP: trying format YUY2 @ 640x480
SETUP: Capture callback set
SETUP: Device is setup and ready to capture.

Event: Code: 0x0d Params: 0, 0
Event: Code: 0x0e Params: 0, 0
Event: Code: 0x03 Params: -2147024891, 0
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by LBerger
close date 2017-05-03 09:54:12.768672


Which camera do you use?

LBerger gravatar imageLBerger ( 2017-05-03 07:42:50 -0600 )edit

i have 2 camera. A cam is inside the laptop. The second cam is a simple cam usb. I have tried them with AMCap and they work. they are 640x480

GiGa.91 gravatar imageGiGa.91 ( 2017-05-03 08:18:51 -0600 )edit

Some antiviruses can lock webcam. If you use one of them you need to manually allow webcam usage.

pi-null-mezon gravatar imagepi-null-mezon ( 2017-05-03 08:27:50 -0600 )edit

Yes check antivurus but have you installed something like MPHC ?

LBerger gravatar imageLBerger ( 2017-05-03 08:35:13 -0600 )edit

I haven't antivirus installed. No, I do not think I have installed MPHC. Do I have to install it? i use

GiGa.91 gravatar imageGiGa.91 ( 2017-05-03 08:39:18 -0600 )edit

No don't install it. but try VideoCapture cap(1) instead of 0 for your webcam

LBerger gravatar imageLBerger ( 2017-05-03 08:41:58 -0600 )edit

I have already tried both. The result is the same. Gray screen

GiGa.91 gravatar imageGiGa.91 ( 2017-05-03 08:43:32 -0600 )edit

Which webcam do you use?

LBerger gravatar imageLBerger ( 2017-05-03 08:47:22 -0600 )edit

ok i write the id hardware: 1) USB Camera -> VID 0C45 PID 6340 2) USB2.0 HD UVC WebCam -> VID 04F2 PID B354

GiGa.91 gravatar imageGiGa.91 ( 2017-05-03 08:51:50 -0600 )edit

I have solved. I've installed all Windows updates. I do not know how I got stuffed but I did :)

GiGa.91 gravatar imageGiGa.91 ( 2017-05-03 09:39:07 -0600 )edit