views:

1172

answers:

1

Hi

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 me know of any means to do this.

cheers

+1  A: 

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();
Jacob
Thanks Jacob. This looks promising to me. However I have OpenCV installed on Red Hat machines in our lab and was wondering how to find its version. Is rpm -qa opencv-devel good enough to find version information? I tried looking at the docs.(i.e. FAQs, license, readme) which are part of the installation but none speak of the version. Any clues on that? I tried compiling (by including cv.h and highgui.h) your snippet but it says - ‘Mat’ was not declared in this scope. Am I missing a header or its because I don't have the latest version installed?
Andriyev
Try "using namespace cv".
Jacob
As for the version, I checked out OpenCV from their online SVN repository and compiled it using CMake.
Jacob