How to read all frame in a video without use VideoCapture function in opencv?

asked 2017-09-11 05:32:08 -0600

louis89 gravatar image

hi.I'm beginner in OpenCV and c++.I use below code for video capturing and read a video Which is received from my webcam .I want to use a for loop for read all frame in video(use imread function and for loop ).but I have no idea.can you help me to do this?thanks a lot...

int main(int argc, char* argv[])
{
    VideoCapture cap(0);
    if (!cap.isOpened())
    {
        cout << "Cannot open the video cam" << endl;
        return 0;

    }
 while (1)
    {
        bool bSuccess = cap.read(frame); // read a new frame from video


        if (!bSuccess)
        {
            cout << "Cannot read a frame from video stream" << endl;
            break;
        }
        GaussianBlur(frame, frame, Size(5, 5), 0);
                    imshow("Image", frame);}
              return o;}
edit retag flag offensive close merge delete

Comments

1

what is your question? maybe have a look at: http://answers.opencv.org/question/1/...

VxW gravatar imageVxW ( 2017-09-11 10:19:34 -0600 )edit

can it be, you don't want to get images from you webcam now, but from a video file (like an .avi, or a sequence of images on disk) ?

berak gravatar imageberak ( 2017-09-11 13:40:32 -0600 )edit

@berak I want to get image from my webcam .can I use a LOOP for display all frame One by one؟

louis89 gravatar imagelouis89 ( 2017-09-12 08:15:08 -0600 )edit

sorry, no idea. what you're trying to say ;(

berak gravatar imageberak ( 2017-09-12 08:17:38 -0600 )edit

@berak can i display all frame with another way(except video capture)?

louis89 gravatar imagelouis89 ( 2017-09-12 08:21:23 -0600 )edit

@berak can i display all frame with another way(except video capture)?

louis89 gravatar imagelouis89 ( 2017-09-12 08:21:39 -0600 )edit

the VideoCapture class is the tool to get images from the webcam. so why do you want to avoid it ?

(it does not make any sense)

berak gravatar imageberak ( 2017-09-12 08:35:24 -0600 )edit

if you would like to step frame by frame through a video you can use cv::waitKey(0)

if cv::waitKey(0) & 0xEFFFFF) == 27) break; else read next frame

VxW gravatar imageVxW ( 2017-09-12 08:37:02 -0600 )edit