Hello,
I am trying to do some very simple image processing, using OpenCV to access data from an image. What I want to do is check whether the "B" value of each RGB pixel is greater than 100 - and if so, set that "B" value to 255.
Here is my code:
The problem is, the line which sets the "B" component to zero is never reached. In fact, using a breakpoint in debugging mode, I noticed that the value of data[i * step + j * 3] is always 0...Code:IplImage* image = cvLoadImage("C:\\myPicture.bmp"); // Pointer to OpenCV IplImage structure data = (char*)image -> imageData; // char buffer of image data height = originalImage -> height; // height of image width = originalImage -> width; // width of image step = originalImage -> widthStep; // size in bytes of one line in image for (int i = 0; i < height; i ++) { for (int j = 0; j < width; j ++) { if ((int)data[i * step + j * 3] > 100) { data[i * step + j * 3] = 255; } } }
I have checked that the image is displaying correctly by displaying the image - so it is loading into the buffer ok.
I am able to do SOME image processing, such as inversion, where I simply say :
Also, if I assign a value to an element of the char array, that works too, such as making the entire image dark grey by saying :Code:data[i * step + j * 3] = 255 - data[i * step + j * 3];
BUT, when I actually try to compare the value in the char array to a number, such as in thresholding :Code:data[i * step + j * 3] = 50;
It doesn't work. I have tried checking the values of the array, for example :Code:if (data[i * step + j * 3] > 100) { // do something }
...and it always tells me that the value of x is 0, no matter which element of the image buffer I am accessing.Code:int x = data[i * step + j * 3]; std :: cout << x;
It seems like it is something to do with converting between char and int...any ideas??
Thanks![]()



LinkBack URL
About LinkBacks



