uEye相机:如何拍摄快照?

问题描述:

我必须使用IDS uEye Camera mod.在Visual c ++ 2010和OpenCV下使用UI1210SE-C

I have to use an IDS uEye Camera mod. UI1210SE-C under visual c++ 2010 and OpenCV

每当有客户要求时,我都需要拍照,因此,当我需要时,我需要拍一张简单的照片,然后将其保存在OpenCV Mat图像中.

I need to take a photo every time there is a request by a client, so when I need, I need to take a simple single shot, that I need to save in a OpenCV Mat image.

这是怎么做的?

我已经下载了SDK,并初始化了我的PC可以识别的相机,但是我不知道如何拍照以及如何将其保存在Mat中而没有问题

I have download SDK, and initialize camera, that have been recognized by my PC, but I don't understand how take a photo and how save in a Mat without issues

这是我的实际代码,可以运行,但是图像是红色调并且没有区别,但是第一和第二是相等的,第三是不同的...我不明白为什么...

This is my actual code, works but Images are RED tone and not different, but first and second are equal, third different...I don't understand why...

#define CAPTURE_WIDTH  500
#define CAPTURE_HEIGHT 375

    //Allocazione della matrice immagine per il frame catturato dalla telecamera
Mat frame(CAPTURE_HEIGHT, CAPTURE_WIDTH,CV_8UC3);

//Variabili di inizializzazione della Telecamera IDS uEye UI1220SE-C

HIDS hCam = 1; //Apre Camera con ID 1
int BITS_PER_PIXEL = 24;
int pWidth = CAPTURE_WIDTH;
int pHeight = CAPTURE_HEIGHT; 
SENSORINFO sensor_info;
CAMINFO camera_info;

//puntatori memoria
char* m_pcImageMemory;
int m_lMemoryId;

//Pulizia memoria da foto precedenti
if (hCam != 0){
    is_FreeImageMem (hCam,m_pcImageMemory,m_lMemoryId);
    is_ExitCamera(hCam);
}

//inizializzazione della telecamera 
int initcamera = is_InitCamera(&hCam, NULL);
if(initcamera != IS_SUCCESS)
{
    cout<<endl<<"Impossibile inizializzare la telecamera"<<endl;
    exit(-1);
}

// Acquisisce informazioni riguardanti la telecamera
int camerainfo = is_GetCameraInfo (hCam, &camera_info);
if(camerainfo != IS_SUCCESS)
{
    printf("Impossibile acquisire le informazioni della telecamera");
    exit(-1);
} 
// Acquisisce informazioni riguardanti il sensore della telecamera
int sensorinfo = is_GetSensorInfo (hCam, &sensor_info);
if(sensorinfo != IS_SUCCESS)
{
    printf("Impossibile acquisire le informazioni del sensore");
    exit(-1);
}

//Output informazioni camera/sensore
cout<<endl<<"<<< CARATTERISTICHE DELLA TELECAMERA COLLEGATA >>>"<<endl;
cout<<"Numero seriale: " << camera_info.SerNo << endl;
cout << "Produttore: " << camera_info.ID << endl;
cout << "Modello: " << sensor_info.strSensorName << endl;
cout << "Dimensioni massime per l'immagine: " << sensor_info.nMaxWidth << "x" << sensor_info.nMaxHeight << endl << endl;


//Imposta la modalità di colore BGR24 
int colormode = is_SetColorMode(hCam, IS_CM_BGR8_PACKED);
//int colormode = is_SetColorMode(hCam, IS_SET_CM_RGB24);
if(colormode != IS_SUCCESS)
{
    printf("Impossibile impostare il modo di colore");
    exit(-1);
}

//imposta dimensioni immagini che voglio catturare
int pXPos = (sensor_info.nMaxWidth);
int pYPos = (sensor_info.nMaxHeight);

//Inizializzazione Memoria camera
int rit = is_AllocImageMem (hCam,pXPos,pYPos, 24, &m_pcImageMemory, &m_lMemoryId);
if(rit != IS_SUCCESS)
{
    cout<<endl<<"IMPOSSIBILE INIZIALIZZARE LA MEMORIA"<<endl;
    system("PAUSE");
    exit(-1);
}
cout<<endl<<"Memoria inizializzata"<<endl;

//attivazione della locazione di memoria
int rat = is_SetImageMem (hCam, m_pcImageMemory, m_lMemoryId);
if(rat != IS_SUCCESS)
{
    cout<<endl<<"IMPOSSIBILE ATTIVARE LA MEMORIA"<<endl;
    system("PAUSE");
    exit(-1);
}
cout<<endl<<"Memoria Attivata"<<endl;

//impostazioni correzioni di colore
double strenght_factor = 1.0;
int colorcorrection = is_SetColorCorrection(hCam, IS_CCOR_ENABLE, &strenght_factor);

//impostazioni correzione del bianco
double pval = 1;
int whiteb = is_SetAutoParameter(hCam, IS_SET_ENABLE_AUTO_WHITEBALANCE, &pval, 0);

//impostazione della correzione guadagno
double gval = 1;
int gains = is_SetAutoParameter(hCam, IS_SET_ENABLE_AUTO_GAIN, &gval, 0);


//inizio fase cattura immagine
int dummy;
char *pMem, *pLast;

//ciclo di ripetizione
for (int i=0;i<3;i++)
{

int sho = is_FreezeVideo(hCam, IS_WAIT);
if(sho != IS_SUCCESS)
{
    cout<<endl<<"IMPOSSIBILE ACQUISIRE DALLA TELECAMERA"<<endl;
    system("PAUSE");
    exit(-1);
}
if (sho == IS_SUCCESS){
    int m_Ret = is_GetActiveImageMem(hCam, &pLast, &dummy);
    int n_Ret = is_GetImageMem(hCam, (void**)&pLast);
   }

 IplImage* tmpImg = cvCreateImageHeader(cvSize (pXPos, pYPos), IPL_DEPTH_8U,3); 
 tmpImg->imageData = m_pcImageMemory;
 frame = cv::cvarrToMat(tmpImg);
 imshow("PROVA",frame);
 waitKey(0);

}
//chiusura e pulizia della telecamera
int en = is_ExitCamera(hCam);
 if (en == IS_SUCCESS){
    cout<<endl<<"Camera chiusa correttamente"<<endl;
 } 

is_freezeVideo是执行快照的功能(阅读手册),但我不明白为什么图片是红色的,以及如何在从iplimage传递的mat文件中使用....

is_freezeVideo is the function that doing snapshot (reading manual) but I don't understand why pictures are RED and how use in a mat file insted passing from a iplimage....

预先感谢所有人可以帮助我...

Thanks in advance to all can help me...

嗯,我在PC上测试了您的代码,一切正常.图像保持相同的参数,我得到正确的结果. 也许问题是您没有定义参数文件(.ini).为此,您必须按照手册中的说明自行定义并使用

Hmm I tested your code on my pc and everything is working perfectly. The images are maintaining the same parameters and I get the correct outcome. Maybe the problem is that you don't define a parameter file (.ini). In order to do it you have to define it on your own as is said in the manual and call it with the

INT is_ParameterSet(HIDS hCam, UINT nCommand, void* pParam, UINT cbSizeOfParam)

我在Ubuntu 12.04(适用于C/C ++开发人员的Eclipse IDE)上对其进行了测试:开普勒服务发行版2和ueye版本4.31.

I tested it on Ubuntu 12.04, Eclipse IDE for C/C++ Developers Version: Kepler Service Release 2 with ueye Version 4.31.