访问的负像素值的OpenCV [英] Accessing negative pixel values OpenCV

查看:444
本文介绍了访问的负像素值的OpenCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在OpenCV中的图像上执行过零边缘检测。我模糊和使用cvLaplace(),然后从(0,最大值)缩放。我的问题是:如何访问像素值的图像中以这样的方式来正确识别负值?利用OpenCV的(cvPtr2D)提供的函数返回无符号的字符。任何想法或意见?

I am attempting to perform a zero-crossing edge detection on an image in OpenCV. I blur and use the cvLaplace() then scale it from (0, max). My question is: How can I access the pixel values in that image in such a way as to correctly identify negative values? Using the function provided by OpenCV (cvPtr2D) returns unsigned chars. Any ideas or comments?

感谢您

推荐答案

像素在内部为IPL_DEPTH_8U,这意味着8位无符号的字符,范围从0到255存储但是,你也可以收拾他们作为IPL_DEPTH_16S(符号整数)甚至IPL_DEPTH_32F(单precision浮点数)。

Pixels are stored internally as IPL_DEPTH_8U, which means 8-bit unsigned char, ranging from 0 to 255. But you could also pack them as IPL_DEPTH_16S (signed integer) and even IPL_DEPTH_32F (single precision floating point number).

cvConvertScale()可能会做的工作!但是,如果你想将它手动转换:
<一href=\"http://stackoverflow.com/questions/882066/opencv-need-to-convert-ipl-depth-32s-to-ipl-depth-32f\">http://stackoverflow.com/questions/882066/opencv-need-to-convert-ipl-depth-32s-to-ipl-depth-32f

cvConvertScale() probably will do the job! But if you want to convert it manually: http://stackoverflow.com/questions/882066/opencv-need-to-convert-ipl-depth-32s-to-ipl-depth-32f

的基本思想是创建具有c​​vCreateImage()需要它们是新的图​​像和格式,然后使用cvConvertScale()为原始数据复制到新的格式。最后,你的code可能类似于以下内容:

The basic idea is to create a new image with cvCreateImage() and the format you need them to be, then use cvConvertScale() to copy the original data to new format. In the end, your code might look something like the following:

IplImage* img = cvLoadImage("file.png", CV_LOAD_IMAGE_ UNCHANGED);
// then retrieve size of loaded image to create the new one

IplImage* new_img = cvCreateImage(img_size, IPL_DEPTH_16S, 1);

cvConvertScale(img, new_img, 1/255.0, -128);

我觉得这回答线程的问题。

I think this answers the question of the thread.

回答您的意见,您可以访问的像素信息是这样的:

Answering your comment, you could access the pixel information like this:

IplImage* pRGBImg = cvLoadImage(input_file.c_str(), CV_LOAD_IMAGE_UNCHANGED); 
int width = pRGBImg->width; 
int height = pRGBImg->height;
int bpp = pRGBImg->nChannels; 
for (int i=0; i < width*height*bpp; i+=bpp) 
{
  if (!(i % (width*bpp))) // print empty line for better readability
      std::cout << std::endl;

  std::cout << std::dec << "R:" << (int) pRGBImg->imageData[i] <<  
                          " G:" << (int) pRGBImg->imageData[i+1] <<  
                          " B:" << (int) pRGBImg->imageData[i+2] << " "; 
}

不要忘记投票和纪念这个答案在它没有接受的情况下

Dont forget to vote up and mark this answer as accepted in case it did.

这篇关于访问的负像素值的OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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