Ask Your Question

Dejan's profile - activity

2019-09-30 06:19:34 -0500 received badge  Notable Question (source)
2019-04-18 21:44:36 -0500 received badge  Popular Question (source)
2017-03-22 10:47:21 -0500 received badge  Famous Question (source)
2015-05-13 06:35:26 -0500 received badge  Notable Question (source)
2014-09-10 10:29:25 -0500 received badge  Popular Question (source)
2013-09-20 07:07:22 -0500 asked a question Can't grab frame from webcamera

I am using OpenCV 2.4.6, VS2010 with Windows 7 64 bit. I could not grab frame from the camera. The code below is working fine for avi file, but not working to capture from camera. Can anyone help me, how can I capture the frame? Thanks in advance.......

Actually problem in this portion:

bool bSuccess = cap.read(frame); // read a new frame from video

    if (!bSuccess) //if not success, break loop
    {
        cout << "Cannot read a frame from video file" << endl;
        break;
    }

The full source code:

#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
    VideoCapture cap(0); // open the video camera no. 0

    if(!cap.isOpened())  // if not success, exit program
    {
        cout << "Cannot open the video file" << endl;
        return -1;
    }

    double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
    double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video

    cout << "Frame size : " << dWidth << " x " << dHeight << endl;

    namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

    while(1)
    {
        Mat frame;

        bool bSuccess = cap.read(frame); // read a new frame from video

        if (!bSuccess) //if not success, break loop
        {
            cout << "Cannot read a frame from video file" << endl;
            break;
        }

        imshow("MyVideo", frame); //show the frame in "MyVideo" window

        if(waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
        {
            cout << "esc key is pressed by user" << endl;
            break; 
        }
    }
    return 0;
}
2013-08-22 11:18:40 -0500 commented answer OpenCV can't capture the frame from the webcam.

Hello dear, I submitted the full code in the above comment. Video Capture in ok. but when the frame is capture that time problem happened. When check the if structure for capturing frame that time I got message "Cannot read a frame from video file" and program terminated. Please give a solution about it.

2013-08-22 10:38:48 -0500 commented answer OpenCV can't capture the frame from the webcam.

include "opencv2/highgui/highgui.hpp"

include <iostream>

using namespace cv; using namespace std; int main(int argc, char* argv[]) { VideoCapture cap(0); if (!cap.isOpened())
{ cout << "Cannot open the video file" << endl; return -1; } double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); cout << "Frame size : " << dWidth << " x " << dHeight << endl; namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); while (1) { Mat frame; bool bSuccess = cap.read(frame); if (!bSuccess) { cout << "Cannot read a frame from video file" << endl; break; } imshow("MyVideo", frame); if (waitKey(30) == 27) { cout << "key is pressed" << endl; break; } } return 0; }

2013-08-22 07:20:52 -0500 asked a question OpenCV can't capture the frame from the webcam.

Hello All, I am using OpenCV 2.4.6 with VS2010. I think my webcam can't capture the frame. When I executed the code it has builed successfully. But I am not getting output. I think, when I checked "if(!bSuccess)" its executed and can't capture frame from the webcam. Please help me, how can I resolve it. Thanks in advanced.........

Mat frame;
bool bSuccess = cap.read(frame);
if (!bSuccess)
{
   cout << "Cannot read a frame from video file" << endl;
   break;
}
2013-08-15 14:17:57 -0500 commented answer Program execution switches automatically off when using video capture.

Dear StevenPuttemans, I am trying to execute below example. But after execution, it has generated some problems that I mentioned in above comment. Please give a solution aobut it.

include "opencv2/opencv.hpp"

using namespace cv;

int main(int, char**) { VideoCapture cap(0); if(!cap.isOpened()) return -1;

Mat edges;
namedWindow("edges",1);
for(;;)
{
    Mat frame;
    cap &gt;&gt; frame; 
    cvtColor(frame, edges, CV_BGR2GRAY);
    GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
    Canny(edges, edges, 0, 30, 3);
    imshow("edges", edges);
    if(waitKey(30) &gt;= 0) break;
}
return 0;

}

2013-08-14 15:49:55 -0500 commented answer Program execution switches automatically off when using video capture.

Thanks a lot for your help. I am trying to execute new C++ code for video capture. But its not working well. No build solution error. program execution is ok and webcam is also open. But I am getting errors below:

Command Prompt Showing Message: OpenCV Error: Assertion Failed (scn == 3 || scn == 4) is unknown function, file......\imgproc\src\color.cpp

Another Message box Came showing message:

Unhandled exception at 0x7681b727 in cv.exe: Microsoft C++ exception: cv::Exception at memory location 0x003bb414..

2013-08-14 14:22:10 -0500 commented answer Program execution switches automatically off when using video capture.

Dear StevenPuttemans, I have found the errors of video capture. I have used the code below: CvCapture* capture = cvCaptureFromCAM(0);
if(!cvQueryFrame(capture)) { cout<<"Video capture failed, please check the camera."<<endl; } else { cout<<"Video camera capture status: OK"<<endl; }

After execute the code, my webcam is open but i get the first error message "Video capture failed, please check the camera" that means webcam is not working. But my webcam is open and i get the video. Where is the problem? How can I solve it? Please help me.

Notice: I am using Laptop webcam, OpenCV 2.4.6 with Visual Studio 2010.

2013-08-14 13:27:14 -0500 commented answer Program execution switches automatically off when using video capture.

Dear StevenPuttemans, thanks for your comment. Sorry for sharing another person's source code. I have some source code that size are bigger than 800 characters. In your site, 800 characters limitation for a comment. I couldn't submit my source code in the comment. For that why, I shared this code. Again sorry for that.

2013-08-12 13:06:11 -0500 commented answer Program execution switches automatically off when using video capture.

The program is about virtual mouse control. I am using the source code from the link below. Please check it and reply, where is the actual fault?

https://github.com/wncc-itsp-2013/p1w13-virtual-mouse-using-hand-gesture

2013-08-12 08:25:45 -0500 asked a question Program execution switches automatically off when using video capture.

I am using OpenCV 2.4.6 with Visual Studio 2010. I have a problem in video capturing.

The program has no errors and no warnings when building the solution. When I start debugging the program, it starts executing, switches camera on and then automatically off, and finally closes down command prompt. I am not getting any results back. But image processing and other program execution is ok.

Can anyone help me about it?