pixel value and position

asked 2013-01-14 14:54:14 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

Hi OpenCV. I need to know the location and color of each pixel in my image. I tried this program:

CvScalar pixel;

for (i=0;i<(src->height);i++)

{

for (j=0;j<(src->width);j++)

{

    //printf ("i=%d,j=%d\n",i,j);
    pixel=cvGet2D(src,i,j);
    printf("B=%f, G=%f, R=%f\n",pixel.val[0],pixel.val[1],pixel.val[2]); 
    printf ("hight=%d\n",src->height);

}

} but it returns me only the pixel values ​​of half of the last line of the image sampled. What's the problem in my software? Please Help Me :)

edit retag flag offensive close merge delete

Comments

Do you mean it displays all other lines OK, and only half the last line? Or is all you're getting is half the last line? Can you tell if the output you are getting is correct? If you could post your output, it might help.

matt.hammer gravatar imagematt.hammer ( 2013-01-14 15:16:20 -0500 )edit

Your code works fine in my PC and it print all the pixel value of src. Why you are printing src->height always in the for loop it always gives the same value.

Haris gravatar imageHaris ( 2013-01-14 23:22:40 -0500 )edit