opencv video capturing and saving using webcam using intel galileo

asked 2014-09-09 00:33:14 -0600

kishan gravatar image

hello all,

I am working on intel galileo. Now, I want to capture video from webcam and I want to save it using opencv in my board.

but I am facing error in this task,

my code

#include <highgui.h>  
#include "opencv2/highgui/highgui.hpp"  
#include <cv.h>  
#include <time.h>  
#include <stdio.h>  
#include <unistd.h>  
int main(int argc, char** argv)   
{  
    int i=0,j=0;  

         CvCapture* capture = cvCaptureFromCAM(0);  

    cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 320);  
    cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 240);  

    CvSize size = cvSize((int)cvGetCaptureProperty( capture,CV_CAP_PROP_FRAME_WIDTH),(int)cvGetCaptureProperty( capture,CV_CAP_PROP_FRAME_HEIGHT));  

    IplImage* frame = cvQueryFrame( capture );  

    CvVideoWriter *writer = cvCreateVideoWriter( "video.avi" ,CV_FOURCC('M','J','P','G'), 10 ,size, 1);  
    if(!writer)  
        printf("errorrrrrrrrrrrrrrrrrrrrrr\n");  

         while(1)  
         {      
            frame = cvQueryFrame(capture);  
        if(!frame) break;  
        j = cvWriteFrame(writer, frame);  
        printf("writer = %d\n",j);  
        if(i==10)  
        {  
            cvReleaseCapture(&capture);  
            break;  
        }  
        else  
        i++;  
        }  

}

I have attached my c code for video capturing and saving using opencv

I have shown output of this this below

================================================================

root@clanton:/# ./video

VIDIOC_QUERYMENU: Invalid argument

VIDIOC_QUERYMENU: Invalid argument

VIDIOC_QUERYMENU: Invalid argument

VIDIOC_QUERYMENU: Invalid argument

VIDIOC_QUERYMENU: Invalid argument

VIDIOC_QUERYMENU: Invalid argument

VIDIOC_QUERYMENU: Invalid argument

VIDIOC_QUERYMENU: Invalid argument

VIDIOC_QUERYMENU: Invalid argument

VIDIOC_QUERYMENU: Invalid argument

VIDIOC_QUERYMENU: Invalid argument

VIDIOC_QUERYMENU: Invalid argument

VIDIOC_QUERYMENU: Invalid argument

VIDIOC_QUERYMENU: Invalid argument

errorrrrrrrrrrrrrrrrrrrrrr

writer = 0

writer = 0

writer = 0

writer = 0

writer = 0

writer = 0

writer = 0

writer = 0

writer = 0

writer = 0

root@clanton:/#

================================================================

here my cvCreateVideoWriter function fails each and every time

I have tried many things but not able to solve this error

please give me some solution

Thanx in advance

edit retag flag offensive close merge delete

Comments

1

... please stop living under a rock, and use opencv's c++ api.

berak gravatar imageberak ( 2014-09-09 01:47:24 -0600 )edit

include "opencv2/opencv.hpp"

include <iostream>

using namespace std; using namespace cv;

int main() { int i=0;

VideoCapture vcap(0);
  if(!vcap.isOpened()){
         cout &lt;&lt; "Error opening video stream or file" &lt;&lt; endl;
         return -1;
  }

int frame_width= vcap.get(CV_CAP_PROP_FRAME_WIDTH); int frame_height= vcap.get(CV_CAP_PROP_FRAME_HEIGHT); VideoWriter video("out.avi",CV_FOURCC('M','J','P','G'),10, Size(frame_width,frame_height),true);

if(!video.isOpened()) { cout << "Errroooooooorrrrrrr" << endl;

}

while(1){

   Mat frame;
   vcap &gt;&gt; frame;
   video.write(frame);
   if(i==20)
   {
       char c = (char)waitKey(33);
       break;
   }
   else
       i++;
}

return 0; }

kishan gravatar imagekishan ( 2014-09-09 02:05:35 -0600 )edit

above is my c++ program it gives me an error as shown below

============================================

root@clanton:/kishan# ./v++ VIDIOC_QUERYMENU: Invalid argument VIDIOC_QUERYMENU: Invalid argument VIDIOC_QUERYMENU: Invalid argument VIDIOC_QUERYMENU: Invalid argument VIDIOC_QUERYMENU: Invalid argument VIDIOC_QUERYMENU: Invalid argument VIDIOC_QUERYMENU: Invalid argument Errroooooooorrrrrrr root@clanton:/kishan# ls

==================================================

kishan gravatar imagekishan ( 2014-09-09 02:07:05 -0600 )edit
1

Now I came out of the rock.. now you give me solution

kishan gravatar imagekishan ( 2014-09-09 02:11:26 -0600 )edit
1

try -1 instead of the fourcc, and see if it gives you a list of supported codecs

berak gravatar imageberak ( 2014-09-09 02:40:28 -0600 )edit

I have tried it but it is not showing me list of codec

kishan gravatar imagekishan ( 2014-09-09 03:43:05 -0600 )edit

the codec is not installed on your system ... try to figure out which codec packs exist for your system.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-09-09 08:02:54 -0600 )edit

how to find which codecs are already installed in my system?

kishan gravatar imagekishan ( 2014-09-10 01:52:54 -0600 )edit

I am looking for a universal way myself. Have been installing codec packs to make it work on windows, on linux no experience in it yet.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-09-10 03:10:09 -0600 )edit