Ask Your Question
0

Ueye usb 1540LE monocrome live streaming with opencv 3

asked 2015-12-04 03:14:22 -0600

updated 2015-12-04 04:22:58 -0600

LBerger gravatar image

Hi there,

i have been trying to start ueye usb 1540 LE monochrome camera using opencv on ubuntu 14.04. program runs and camera is initialised also, memory is also allocated, but my window is showing blank images so far.any clues ??

here is my code... got this code from link text

//start camera//

void initializeCameraInterface(HIDS* hCam_internal)
{
 // Open cam and see if it was succesfull
INT nRet = is_InitCamera (hCam_internal, NULL);

if (nRet == IS_SUCCESS){
    cout << "Camera initialized!" << endl;
}

// Setting the pixel clock to retrieve data
UINT nPixelClockDefault = 24;
nRet = is_PixelClock(*hCam_internal, IS_PIXELCLOCK_CMD_SET, (void*)&nPixelClockDefault, sizeof(nPixelClockDefault));

if (nRet == IS_SUCCESS){
    cout << "Camera pixel clock succesfully set!" << endl;
}else if(nRet == IS_NOT_SUPPORTED){
    cout << "Camera pixel clock setting is not supported!" << endl;
}

// Set the color mode of the camera
INT colorMode = IS_CM_MONO8;
nRet = is_SetColorMode(*hCam_internal,colorMode);

if (nRet == IS_SUCCESS){
    cout << "Camera color mode succesfully set!" << endl;
}

// Store image in camera memory --> option to chose data capture method
// Then access that memory to retrieve the data
INT displayMode = IS_SET_DM_DIB;
nRet = is_SetDisplayMode (*hCam_internal, displayMode);

if (nRet == IS_SUCCESS){
    cout << "display mode succesfully set!" << endl;
}
}


// Capture a frame and push it in a OpenCV mat element

Mat getFrame(HIDS* hCam, int width, int height, cv::Mat& mat)
 {
// Allocate memory for image

char* pMem = NULL;
int memID = 0;
   if( is_AllocImageMem(*hCam, width, height, 8, &pMem, &memID) == IS_SUCCESS)

   {

  //cout<< "allocation successful" <<endl;

   };

// Activate the image memory for storing the frame captured
// Grabbing the image
// Getting the data of the frame and push it in a Mat element
 is_SetImageMem(*hCam, pMem, memID);
// is_FreezeVideo(*hCam, IS_WAIT);

//is_SetImageSize(*hCam,width,height);
//is_SetImagePos(*hCam, 0, 0);

is_FreezeVideo(*hCam, IS_WAIT);

//cout<< "debug 1"<<endl;

VOID* pMem_b;
int retInt = is_GetImageMem(*hCam, &pMem_b);

if (retInt != IS_SUCCESS) {
    cout << "Image data could not be read from memory!" << endl;
}
else{
//cout << "Image data  read from memory!" << endl;
}

if (memcpy(mat.ptr(), pMem_b, sizeof(mat) ));
    cout<<"memory copied"<<endl;

    return mat;

}

int main()
{

// ---------------------------------------------------------------------------------------------------------------
// START BY CONFIGURING THE INTERFACE WITH THE UEYE CAMERA
// ---------------------------------------------------------------------------------------------------------------

// Camera initialisation
// Index 0 means taking the first camera available
HIDS hCam = 0;
initializeCameraInterface(&hCam);
 namedWindow("test interface", CV_WINDOW_AUTOSIZE);
// ---------------------------------------------------------------------------------------------------------------
// CAPTURE DATA AND PROCESS
// ---------------------------------------------------------------------------------------------------------------

while(true){
// Create an image and grab a frame
    Mat current_image (400, 400, CV_8UC1);
    getFrame(&hCam, 400, 400, current_image);


    // PERFORM YOUR OPENCV PROCESSING HERE!
    // Visualise the data
    imshow("test_interface", current_image);

    // Check if we need to stop processing
    if ( (int)waitKey(10) >= 0 ){
        break;
    }
}

// Release the camera again
is_ExitCamera(hCam);

return 0;
}
edit retag flag offensive close merge delete

Comments

1

@StevenPuttemans I can't believe you have your own tag! hahaha

LorenaGdL gravatar imageLorenaGdL ( 2015-12-04 04:27:23 -0600 )edit

Oh wow, someone actually uses my code. First of all, without any decent debugging output or errors we cannot help you. Secondly, the code snippet was ONLY tested using the AVT Guppy camera and was confirmed to work there, but since I had no access to other camera's I have no idea why it is not working at first sight.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-12-04 04:36:07 -0600 )edit
1

@LorenaGdL ahahahahahaha just noticed :D clearly a show on how important people find my input :D

StevenPuttemans gravatar imageStevenPuttemans ( 2015-12-04 04:37:03 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-12-14 13:03:41 -0600

leorich gravatar image

updated 2017-12-14 15:56:42 -0600

@StevenPuttemans I was just using this same piece of code and the only issue was the preallocated memory was the wrong size. I checked each function call in the getFrame function similar to the way you checked the functions in the initialization function and that gave me the error codes needed to solve the problem. So I can say that it is confirmed to work with the UI-3241LE-NIR-GL. Thanks for the code!

edit flag offensive delete link more

Comments

You are welcome. Could you add the details of your camera and preallocation memory changes you need to made to this topic?

StevenPuttemans gravatar imageStevenPuttemans ( 2017-12-15 04:28:52 -0600 )edit
1

Sure, I changed the width and height to match my cameras max width and height (1280,1024), which correctly allocated memory in the isAllocImageMem function. I will say, for continuous capture/ streaming I think there is a much more efficient way to handle things other than the is_FreezeVideo(). I'm attempting to figure that out now..

leorich gravatar imageleorich ( 2017-12-18 10:35:47 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-12-04 03:14:22 -0600

Seen: 1,232 times

Last updated: Dec 14 '17