开发者

OpenCV: Fetch color, intensity and texture of an image

I'm new to OpenCV and just started sifting through the APIs. I intend to fetch the color, intensity and texture values of each pixel constituting the image. I was fiddling with the structure - IplImage to start with but couldn't make much progress.

Please let m开发者_运维技巧e know of any means to do this.

cheers


Have you tried OpenCV 2.0? They have a new C++ interface which makes things much easier. You can use their new Mat class to load images, access pixels efficiently, etc. It's much cleaner than IplImage fun. I use \doc\opencv.pdf as my reference to anything I need. It's got tutorials, and examples with the new C++ interface, etc. - enough and more to get you started.

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

Here's some demo code to get you started: (I've 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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜