Skip to content

Instantly share code, notes, and snippets.

@hasanaga
Created December 27, 2017 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasanaga/4aca3a3ca1198a45554547fc79b476c2 to your computer and use it in GitHub Desktop.
Save hasanaga/4aca3a3ca1198a45554547fc79b476c2 to your computer and use it in GitHub Desktop.
Read Frame from uEye camera with uEye SDK, OpenCv
#include <QtCore/QCoreApplication>
#include <uEye.h>
#include <uEye_tools.h>
#include <ueye_deprecated.h>
#include <wchar.h>
#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include <opencv2/highgui/highgui.hpp>
#include <QDebug>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
HIDS hCam = 0;
char* imgMem;
int memId;
if(is_InitCamera (&hCam, NULL)!= IS_SUCCESS){
return 0;
}
int img_width=640, img_height=360, img_bpp=24, img_step, img_data_size;
is_AllocImageMem(hCam, img_width, img_height, img_bpp, &imgMem, &memId);
is_SetImageMem (hCam, imgMem, memId);
is_SetDisplayMode (hCam, IS_SET_DM_DIB);
is_SetColorMode (hCam, IS_CM_RGB8_PACKED);
is_SetImageSize (hCam, img_width, img_height);
double enable = 1;
double disable = 0;
is_SetAutoParameter (hCam, IS_SET_ENABLE_AUTO_GAIN, &enable, 0);
is_SetAutoParameter (hCam, IS_SET_ENABLE_AUTO_WHITEBALANCE, &enable, 0);
is_SetAutoParameter (hCam, IS_SET_ENABLE_AUTO_FRAMERATE, &disable, 0);
is_SetAutoParameter (hCam, IS_SET_ENABLE_AUTO_SHUTTER, &disable, 0);
is_SetAutoParameter (hCam, IS_SET_ENABLE_AUTO_SENSOR_GAIN, &enable, 0);
is_SetAutoParameter (hCam, IS_SET_ENABLE_AUTO_SENSOR_WHITEBALANCE,&enable,0);
is_SetAutoParameter (hCam, IS_SET_ENABLE_AUTO_SENSOR_SHUTTER, &disable, 0);
double FPS,NEWFPS;
FPS = 15;
double fps;
is_SetFrameRate(hCam,FPS,&NEWFPS);
double parameter = 50;
int error = is_Exposure(hCam, IS_EXPOSURE_CMD_SET_EXPOSURE, (void*) &parameter, sizeof(parameter));
if (error != IS_SUCCESS) {
qDebug() << "): failed" <<parameter;
}
error = is_Exposure(hCam, IS_EXPOSURE_CMD_GET_EXPOSURE, (void*) &parameter, sizeof(parameter));
UINT uiCaps = 0;
INT nRet = is_Focus (hCam, FDT_CMD_GET_CAPABILITIES, &uiCaps, sizeof (uiCaps) );
if (nRet == IS_SUCCESS && (uiCaps & FOC_CAP_AUTOFOCUS_SUPPORTED))
{
qDebug() << "If supported, enable auto focus";
nRet = is_Focus (hCam, FOC_CMD_SET_DISABLE_AUTOFOCUS, NULL, 0);
}
nRet = is_SetGamma(hCam,600);
enable = 2;
char filename[512];
for(int ii=0; ii<100; ii++)
{
if(is_FreezeVideo(hCam, IS_WAIT) == IS_SUCCESS){
void *pMemVoid; //pointer to where the image is stored
is_GetImageMem (hCam, &pMemVoid);
IplImage * img;
img=cvCreateImage(cvSize(img_width, img_height), IPL_DEPTH_8U, 3);
img->nSize=112;
img->ID=0;
img->nChannels=3;
img->alphaChannel=0;
img->depth=8;
img->dataOrder=0;
img->origin=0;
img->align=4;
img->width=img_width;
img->height=img_height;
img->roi=NULL;
img->maskROI=NULL;
img->imageId=NULL;
img->tileInfo=NULL;
img->imageSize=3*img_width*img_height;
img->imageData=(char*)pMemVoid; //the pointer to imagaData
img->widthStep=3*img_width;
img->imageDataOrigin=(char*)pMemVoid; //and again
//now you can use your img just like a normal OpenCV image
cvNamedWindow( "A", 1 );
cvShowImage("A",img);
cv::waitKey(1);
}
else{
qDebug() << "ERROR FREEZE";
}
}
is_ExitCamera(hCam);
return a.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment