OpenCV的:在内存中转换指针图像 [英] OpenCV : convert the pointer in memory to image

查看:408
本文介绍了OpenCV的:在内存中转换指针图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个采集卡,可以得到图像,并显示在屏幕上,使用下列code

I have a grabber which can get the images and show them on the screen with the following code

while((lastPicNr = Fg_getLastPicNumberBlockingEx(fg,lastPicNr+1,0,10,_memoryAllc))<200) {                                                           
                iPtr=(unsigned char*)Fg_getImagePtrEx(fg,lastPicNr,0,_memoryAllc);                  
                ::DrawBuffer(nId,iPtr,lastPicNr,"testing");                                         }

,但我想使用指针来的图像数据,并与OpenCV中显示它们,因为我需要做的像素的处理。我的相机是CCD单摄像机和像素的深度为8位。我是新来的OpenCV,有没有任何OpenCV的选项,可以得到(无符号字符*)返回Fg_getImagePtrEx(FG,lastPicNr,0,_memoryAllc);和DISPLY在屏幕上?或从IPTR指针获取数据的允许我使用的图像数据吗?

but I want to use the pointer to the image data and display them with OpenCV, cause I need to do the processing on the pixels. my camera is a CCD mono camera and the depth of the pixels is 8bits. I am new to OpenCV, is there any option in opencv that can get the return of the (unsigned char*)Fg_getImagePtrEx(fg,lastPicNr,0,_memoryAllc); and disply it on the screen? or get the data from the iPtr pointer an allow me to use the image data?

推荐答案

创建的IplImage 无符号字符* raw_data 需要2重要批示:<一href=\"http://opencv.itseez.com/modules/core/doc/old_basic_structures.html?highlight=cvsetdata#IplImage%2a%20cvCreateImageHeader%28CvSize%20size,%20int%20depth,%20int%20channels%29\"><$c$c>cvCreateImageHeader()和<一个href=\"http://opencv.itseez.com/modules/core/doc/old_basic_structures.html?highlight=cvsetdata#void%20cvSetData%28CvArr%2a%20arr,%20void%2a%20data,%20int%20step%29\"><$c$c>cvSetData():

Creating an IplImage from unsigned char* raw_data takes 2 important instructions: cvCreateImageHeader() and cvSetData():

// 1 channel for mono camera, and for RGB would be 3
int channels = 1; 
IplImage* cv_image = cvCreateImageHeader(cvSize(width,height), IPL_DEPTH_8U, channels);
if (!cv_image)
{
    // print error, failed to allocate image!
}

cvSetData(cv_image, raw_data, cv_image->widthStep);

cvNamedWindow("win1", CV_WINDOW_AUTOSIZE);
cvShowImage("win1", cv_image);
cvWaitKey(10);

// release resources
cvReleaseImageHeader(&cv_image);
cvDestroyWindow("win1");

我没有测试code,但你正在寻找的code路线图是存在的。

I haven't tested the code, but the roadmap for the code you are looking for is there.

这篇关于OpenCV的:在内存中转换指针图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆