Ask Your Question
0

Which OpenCV function for Analog camera?

asked 2013-10-16 06:41:16 -0600

Hitendra gravatar image

updated 2013-11-11 05:38:58 -0600

image descriptionWhich OpenCV's function support the analog camera for live streaming?

Please give me the answer.

I tried CvCapture and VideoCapture functions of OpenCV. It works for USB camera but did not work for Analog camera.

I tried VideoInput function.It works well with analog camera but i want to use opencv inbuilt function. So please help me. Thanks for your time.

Thanks for your reply.

This is my code and I have used videoInput function and it works well.

#include "stdafx.h"
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include "videoInput.h"
#include <opencv2/imgproc/imgproc.hpp>


using namespace cv;
using namespace std;

int main(int, char**)
{
   videoInput VI;
    int numDevices = VI.listDevices();
    //int device1= 0;
    VI.setup(0);

    unsigned char* yourBuffer = new unsigned char[VI.getSize(0)];

    IplImage* colourImage = cvCreateImage(cvSize(320,240),8,3);

    while(1)
    {
        VI.grabFrame(0, yourBuffer);
        colourImage->imageData = (char*)yourBuffer;
        cvConvertImage(colourImage, colourImage, 3);

        cvShowImage("test",colourImage);

        if( cvWaitKey(10) == 27) 
            break;
    }
    return 0;
}

End of code.

Next code using video capture function which is opencv function.But this function not support the analog camera.

start of code

int main() {
VideoCapture stream1(-1);   //0 is the id of video device.0 if you have only one camera.

    if (!stream1.isOpened()) { //check if video device has been initialised
        cout << "cannot open camera";
        return 0;
    }

//unconditional loop
    while (true) {
        Mat cameraFrame;
        stream1.read(cameraFrame);
        imshow("cam", cameraFrame);
        if (waitKey(30) >= 0)
        break;
    }
    return 0;
}

end of code

And last code using cvcapture and it is also opencv function and it is also not support analog camera.

start of code is

char key;
int main()
{
    cvNamedWindow("Camera_Output", 1);    //Create window
    CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY);  //Capture using any camera connected to your system
    while(1){ //Create infinte loop for live streaming

        IplImage* frame = cvQueryFrame(capture); //Create image frames from capture
        cvShowImage("Camera_Output", frame);   //Show image frames on created window
        key = cvWaitKey(10);     //Capture Keyboard stroke
        if (char(key) == 27){
            break;      //If you hit ESC key loop will break.
        }
    }
    cvReleaseCapture(&capture); //Release capture.
    cvDestroyWindow("Camera_Output"); //Destroy Window
    return 0;
}

End of code

Please help me.

edit retag flag offensive close merge delete

Comments

1

First of all, the amount of information you are providing is dramatically low. Specify some sample code, specify your camera you are using, the system you are working on, ... Next you should know that most analog camera devices return data to your pc, and have drivers to convert that data in a digital stream. Camera specific API will mostly give you the chance of retrieving the data stream, which is not always possible in openCV, and then you just pass the data to openCV for processing.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-10-17 06:04:51 -0600 )edit

As a suggestion, never use the old C - API, so skip that and try to create a solution using the C++ API :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-10-18 03:33:12 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
2

answered 2013-10-18 04:52:25 -0600

berak gravatar image

hi hitendra,

what's puzzling me here is , that videoInput is actually part of opencv, and should be used internally, when you try VideoCapture cap(0);or similar.

can you try 2 things ?

  • specify dshow explicitly: VideoCapture cap(0 + CV_CAP_DSHOW);

  • see, if highgui was built with dshow support:

    cout << cv::getBuildInformation() << endl;

(somewhere at the bottom should be : DirectShow: YES )

edit flag offensive delete link more

Comments

Thanks for your reply.I tried but VideoCapture cap(0 + CV_CAP_DSHOW); is not support.

Hitendra gravatar imageHitendra ( 2013-10-21 23:24:41 -0600 )edit
0

answered 2013-10-18 03:08:25 -0600

What kind of HW device are you using to connect the analog cam ? I don't think that will have any difference between Web cam and usb capture for example... Try to connect just 1 device to the system and use

VideoCapture Device(0);
edit flag offensive delete link more

Comments

VideoCapture stream1(-1); like he said, this piece of code is incorrect. Please just try to connect to 0 if this is the only cam on your system, else connect to 1 or 2. The -1 option is wrong here.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-10-18 03:34:19 -0600 )edit

Thanks for your reply. I have put VideoCapture Device(0); and VideoCapture stream1(0); but both are not working.

Hitendra gravatar imageHitendra ( 2013-10-21 23:21:43 -0600 )edit

I get the same result when using a multi channel PCIe video grabber. The HW is supported under Directshow an works accordingly and therefor I believe it should be supported in OpenCV. In OpenCV however empty frames are returned. Basic Funtions used: VideoCapture vidIn; vidIn.open(CV_CAP_DSHOW + port); ... Mat frameCam; for (;;) //Show the image captured in the window and repeat { vidIn >> frameCam; if (frameCam.empty()){ cout << "Frame is empty: " << frameEmpty++ << "times." << endl; if (frameEmpty >= 10) { vidIn.release(); return -1; } } else { imshow(VID_IN, frameCam); } Any ideas why this is not working in OpenCV?

Andries gravatar imageAndries ( 2014-03-06 02:08:41 -0600 )edit

Question Tools

Stats

Asked: 2013-10-16 06:41:16 -0600

Seen: 2,024 times

Last updated: Nov 11 '13