gpt4 book ai didi

c - uEye 相机和 OpenCV 内存访问

转载 作者:太空宇宙 更新时间:2023-11-03 21:54:12 26 4
gpt4 key购买 nike

我使用 35MM EO 百万像素固定 FL 镜头爱特蒙特光学相机、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);

}

谢谢

最佳答案

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

问候,斯里尼瓦斯

关于c - uEye 相机和 OpenCV 内存访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19120198/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com