如何将8位OpenCV IplImage *转换为32位IplImage *? [英] How to convert an 8-bit OpenCV IplImage* to a 32-bit IplImage*?

查看:243
本文介绍了如何将8位OpenCV IplImage *转换为32位IplImage *?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将8位IplImage转换为32位IplImage.使用网络上的文档,我尝试了以下操作:

I need to convert an 8-bit IplImage to a 32-bits IplImage. Using documentation from all over the web I've tried the following things:

// general code
img2 = cvCreateImage(cvSize(img->width, img->height), 32, 3);
int height    = img->height;
int width     = img->width;
int channels  = img->nChannels;
int step1     = img->widthStep;
int step2     = img2->widthStep;
int depth1    = img->depth;
int depth2    = img2->depth;
uchar *data1   = (uchar *)img->imageData;
uchar *data2   = (uchar *)img2->imageData;

for(h=0;h<height;h++) for(w=0;w<width;w++) for(c=0;c<channels;c++) {
   // attempt code...
}

// attempt one
// result: white image, two red spots which appear in the original image too.
// this is the closest result, what's going wrong?!
// see: http://files.dazjorz.com/cache/conversion.png
((float*)data2+h*step2+w*channels+c)[0] = data1[h*step1+w*channels+c];

// attempt two
// when I change float to unsigned long in both previous examples, I get a black screen.

// attempt three
// result: seemingly random data to the top of the screen.
data2[h*step2+w*channels*3+c] = data1[h*step1+w*channels+c];
data2[h*step2+w*channels*3+c+1] = 0x00;
data2[h*step2+w*channels*3+c+2] = 0x00;

// and then some other things. Nothing did what I wanted. I couldn't get an output
// image which looked the same as the input image.

如您所见,我真的不知道自己在做什么.我很想找出答案,但是如果我能正确完成,我会更喜欢它. 感谢您的帮助!

As you see I don't really know what I'm doing. I'd love to find out, but I'd love it more if I could get this done correctly. Thanks for any help I get!

推荐答案

也许这

Perhaps this link can help you?

编辑,用于对OP和评论的第二次编辑

Edit In response to the second edit of the OP and the comment

您尝试过

float value = 0.5

代替

float value = 0x0000001;

我认为浮动颜色值的范围从0.0到1.0,其中1.0是白色.

I thought the range for a float color value goes from 0.0 to 1.0, where 1.0 is white.

这篇关于如何将8位OpenCV IplImage *转换为32位IplImage *?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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