uEye Camera和OpenCV Memory Access

时间:2013-10-01 15:28:50

标签: c opencv camera

我使用35MM EO百万像素固定FL镜头Edmund光学相机,OpenCV 2.4.6和Ubuntu 12.04 LTS作为我的开发环境。我也用C来开发,而不是C ++。相机有一个我正在关注的API,我相信我已经正确设置了所有内容。我初始化相机,设置内存位置,并冻结视频。然后我使用OpenCV从内存中获取图像,但我的图像与它应该是什么样的(可能在下面看到)。我的图像数据是否从垃圾内存位置提取数据?如何访问“is_FreezeVideo”保存的图像以进行OpenCV完成的图像处理?打印出的图像可以在此处查看http://i.imgur.com/kW6aqB3.png

我正在使用的代码如下。

#include "../Include/Camera.h"
#include <wchar.h>
#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
//#include <opencv2/opencv.hpp>
#include <ueye.h>

// uEye variables
HIDS m_hCam;                                    // handle to room
HWND m_hWndDisplay;                             // handle to diplay window
int m_Ret;                                      // return value of uEye  SDK functions
int m_nColorMode = 0;                               // Y8/RGB16/RGB24/REG32
int m_nBitsPerPixel=8;                          // number of bits needed store one pixel
int m_nSizeX = 1280;                             // width of video
int m_nSizeY = 1024;                             // height of video
int m_lMemoryId;                                // grabber memory - buffer   ID
char* m_pcImageMemory;                          // grabber memory - pointer to buffer
int m_nRenderMode = IS_RENDER_FIT_TO_WINDOW;    //render  mode

void getAzimuth(){

}
void getElevation(){

}
void initializeCamera(){

    if (m_hCam !=0 ) {
        //free old image mem.
        is_FreeImageMem (m_hCam, m_pcImageMemory, m_lMemoryId);
        is_ExitCamera (m_hCam);
    }

    // init room
    m_hCam = (HIDS) 0;    // open next room
    m_Ret = is_InitCamera (&m_hCam, NULL);    // init room

    if (m_Ret == IS_SUCCESS) {
        // retrieve original image size
        SENSORINFO sInfo;
        is_GetSensorInfo (m_hCam, &sInfo);
        m_nSizeX = sInfo.nMaxWidth;
        m_nSizeY = sInfo.nMaxHeight;

        printf("Width: %d Height: ", m_nSizeX, m_nSizeY);

        // setup the color depth to the current windows setting
        is_GetColorDepth (m_hCam, &m_nBitsPerPixel, &m_nColorMode);
        is_SetColorMode (m_hCam, m_nColorMode);

        //printf ("m_nBitsPerPixel=%i  m_nColorMode=%i \n", m_nBitsPerPixel, IS_CM_BAYER_RG8);

        // memory initialization
        is_AllocImageMem (m_hCam, m_nSizeX, m_nSizeY, m_nBitsPerPixel, &m_pcImageMemory, &m_lMemoryId);
        //set memory active
        is_SetImageMem (m_hCam, m_pcImageMemory, m_lMemoryId);
        // display initialization
        is_SetImageSize (m_hCam, m_nSizeX, m_nSizeY);
        is_SetImagePos(m_hCam, 0, 0);
        is_SetDisplayMode (m_hCam, IS_SET_DM_DIB);
    } else {
        printf("No Camera Initialized! %c", 10);

    }
if (m_hCam !=0) {
    INT dummy;
    char *pMem, *pLast;
    double fps = 0.0;

    if (is_FreezeVideo (m_hCam, IS_WAIT) == IS_SUCCESS) {
        m_Ret = is_GetActiveImageMem(m_hCam, &pLast, &dummy);
        m_Ret = is_GetImageMem(m_hCam, (void**)&pLast);

    }

    IplImage* tmpImg = cvCreateImageHeader (cvSize (m_nSizeX, m_nSizeY), IPL_DEPTH_8U, 1);
    tmpImg->imageData = &m_pcImageMemory;

    cvNamedWindow("src",1);
    cvShowImage("src",tmpImg);

    cvWaitKey(0);

}

}

由于

2 个答案:

答案 0 :(得分:0)

您需要使用is_ImageFile函数将图像文件保存为文件名。您可以从is_ImageFile函数中看到示例示例。您可以将其保存为您需要的格式(bmp,png,jpeg)。

的问候, Sreenivas

答案 1 :(得分:0)

问题在于相机属性。设置亮度和其他属性后,我们现在获得实际图像