Ask Your Question
0

VideoCapture from unsupported API

asked 2020-04-05 03:44:02 -0500

SimonKirkman gravatar image

I have two cameras which have their own API which isn’t supported amongst the VideoCaptureAPIs.These cameras do not register as cameras either so they cannot be called up using a camera number as you would with a usb webcam. The cameras api writes the video data to an unsigned char and you can loop the capture sequence to get the data. I was wondering if there was a way to get a live video stream using the data stored in the char. Below is the description from the cameras API.

Descriptions:

get data from the video buffer.the buffer is very small

you need to call this API as fast as possible, otherwise frame will be discarded

so the best way is maintain one buffer loop and call this API in a loop

please make sure the buffer size is biger enough to hold one image

otherwise the this API will crash

Paras:

int CameraID: this is get from the camera property use the API ASIGetCameraProperty

unsigned char* pBuffer, caller need to malloc the buffer, make sure the size is big enough

    the size in byte:

    8bit mono:width*height

    16bit mono:width*height*2

    RGB24:width*height*3

int iWaitms, this API will block and wait iWaitms to get one image. the unit is ms -1 means wait forever. this value is recommend set to exposure*2+500ms return:

ASI_SUCCESS : Operation is successful

ASI_ERROR_CAMERA_CLOSED : camera didn't open

ASI_ERROR_INVALID_ID :no camera of this ID is connected or ID value is out of boundary

ASI_ERROR_TIMEOUT: no image get and timeout

*************************/

ASICAMERA_API ASI_ERROR_CODE ASIGetVideoData(int iCameraID, unsigned char* pBuffer, long lBuffSize, int iWaitms);

/*************************

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2020-04-05 04:07:27 -0500

berak gravatar image

updated 2020-04-05 04:26:13 -0500

sure this should be possible !

caller need to malloc the buffer, make sure the size is big enough

assuming you know width, height, and the data format, you can prealloc a cv::Mat

(it's also a refcounted smartptr, so you don't have to worry about freeing the memory):

// CV_8U :8bit grayscale, CV_8UC3 :bgr, CV_16U :16bit gray
Mat frame(height, width, CV_8UC1); 
long iBuffSize = frame.total() * frame.elemSize(); // pls check if it fits !

// acquire image, using Mat::data ptr (uchar as well):
auto res = ASIGetVideoData(iCameraID, frame.data, lBuffSize, iWaitms);

// IF it is a 3 channel img, AND it is in RGB order (look it up),
//  you *might* need to convert to BGR (preferred channel order in opencv)
//cvtColor(frame, frame, COLOR_RGB2BGR);
edit flag offensive delete link more

Comments

Thanks for the response. How would I go about displaying this? Create a window then could I use imshow?

SimonKirkman gravatar imageSimonKirkman ( 2020-04-05 04:56:29 -0500 )edit

yes, imshow(), waitKey(10)

(once you have it in a cv::Mat, it's the same as with any other opencv code)

berak gravatar imageberak ( 2020-04-05 04:58:45 -0500 )edit

It worked! Thanks so much for your help!

SimonKirkman gravatar imageSimonKirkman ( 2020-04-05 06:03:29 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-04-05 03:44:02 -0500

Seen: 61 times

Last updated: Apr 05