OpenCV: choosing color, intensity and texture of an image

I'm new to OpenCV and just started sifting through the API. I intend to get the color, intensity and texture values ​​of each pixel that makes up the image. I fiddled with the structure - IplImage to get started but couldn't make much progress.

Please let me know about any means for this.

amuses

+2


source to share


1 answer


Have you tried OpenCV 2.0 ? They have a new C ++ interface that makes things easier. You can use your new Mat class to load images, access pixels efficiently, etc. This is much cleaner than IplImage. I use \ doc \ opencv.pdf as my link for everything I need. He got tutorials and examples with new C ++ interface, etc. - enough and more to get you started.

If you have more specific OpenCV questions please feel free to ask.



Here is some demo code to get you started: (I used the cv namespace):

    // Load the image (looks like MATLAB :) ? )
    Mat M = imread("h:\\lena.bmp");
    // Display
    namedWindow("Lena",CV_WINDOW_AUTOSIZE);
    imshow("Lena",M);
    waitKey();  

    // Crop out rectangle from (100,100) of size (200,200) of the red channel 
    const int offset[2] = {100,100};
    const int dims[2] = {200,200};  
    Mat Red(dims[0],dims[1],CV_8UC1);

    // Read it from M into Red
    uchar* lena = M.data;
    for(int i=0;i<dims[0];++i)
        for(int j=0;j<dims[0];++j)
        {
            // P = i*rows*channels + j*channels + c
            Red.at<uchar>(i,j) = *(lena + (i+offset[0])*M.rows*M.channels() + (j+offset[1])*M.channels()+0);
        }

    //Display
    namedWindow("RedRect",CV_WINDOW_AUTOSIZE);
    imshow("RedRect",Red);
    waitKey();

      

+3


source







All Articles