[英]Error scrolling an image in Opencv
I began working with Opencv in Eclipse with c++, I have been trying to scroll a binary image but I have an error. 我开始使用c ++在Eclipse中使用Opencv,我一直在尝试滚动二进制图像,但是出现错误。 A binary image only has one channel (1,0) or (0,255).
一个二进制图像只有一个通道(1,0)或(0,255)。 In my
if
statement I have results with values like 1 or 254 and I want it to show me the pixel with a white value. 在我的
if
语句中,我得到的结果值为1或254,我希望它向我显示具有白色值的像素。
Here the code: 这里的代码:
IplImage *img=cvLoadImage("/home/delfin/Imágenes/bw.JPG");
IplImage *gray;
IplImage *thresh;
int height=img->height; //altura de la imagen en píxeles
int width=img->width; //anchura de la imagen en píxeles
int anchura_fila =img->widthStep; //calculamos el valor del paso
int i,j,etiqueta;
uchar* data=(uchar *) img->imageData; //cargamos los datos de la imagen en data
printf("Estamos procesando una imagen de %dx%d píxeles \n",width,height);
while(1)
{
gray=cvCreateImage(cvSize(img->width,img->height),IPL_DEPTH_8U,1);
thresh=cvCreateImage(cvSize(img->width,img->height),IPL_DEPTH_8U,1);
cvCvtColor(img,gray, CV_RGB2GRAY);
cvThreshold(gray,thresh,35,255,THRESH_BINARY);
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
if(data[i*anchura_fila+j]!=0) //Si el pixel no es negro
{
printf("El píxel %d %d tiene un valor de: %d \n",j,i,data[i*anchura_fila+j]);
}
}
}
cvShowImage("original", img);
char c = cvWaitKey(0);
if(c == 27) break;
}
And here part of the results: 这是部分结果:
El píxel 523 520 tiene un valor de: 255
El píxel 524 520 tiene un valor de: 255
El píxel 525 520 tiene un valor de: 254
El píxel 526 520 tiene un valor de: 254
El píxel 527 520 tiene un valor de: 254
El píxel 528 520 tiene un valor de: 255
El píxel 529 520 tiene un valor de: 255
El píxel 530 520 tiene un valor de: 255
El píxel 531 520 tiene un valor de: 255
El píxel 532 520 tiene un valor de: 255
El píxel 533 520 tiene un valor de: 255
El píxel 534 520 tiene un valor de: 255
El píxel 535 520 tiene un valor de: 255
El píxel 536 520 tiene un valor de: 255
El píxel 537 520 tiene un valor de: 255
El píxel 538 520 tiene un valor de: 255
El píxel 539 520 tiene un valor de: 255
El píxel 540 520 tiene un valor de: 255
El píxel 541 520 tiene un valor de: 255
El píxel 542 520 tiene un valor de: 255
El píxel 0 521 tiene un valor de: 255
El píxel 1 521 tiene un valor de: 255
El píxel 2 521 tiene un valor de: 255
El píxel 3 521 tiene un valor de: 255
El píxel 4 521 tiene un valor de: 255
El píxel 5 521 tiene un valor de: 255
El píxel 264 521 tiene un valor de: 1
El píxel 265 521 tiene un valor de: 1
El píxel 266 521 tiene un valor de: 1
El píxel 477 521 tiene un valor de: 255
我认为,虽然您假设BW.JPG是二进制图像,但JPEG压缩导致创建的值略有不同,接近0或255。要对此进行测试,可以将图像另存为TIFF或BMP文件,创建后它,然后在您的代码中使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.