Ask Your Question
0

cv::Mat pass by Reference to other share lib

asked 2014-02-21 10:05:49 -0600

Hi All, I am a new comer in OpenCV and currently using OpenCV2.4.8. I got 2 source file which one is the main and the other is a complied as a share lib which call by the main.cpp.

When i try to print the frame.depth() in the main after getting the frame from web cam , it return 0 ( which should be CV_8U ), however , when i pass it to the share lib , it return 1 on the depth() call. I haven't change anything on the Mat , could any one help to explain why the depth and type is changed after passed to the lib and am i passing the reference incorrectly ?

Thanks in advance.

Dick

Here is the source code for Main.cpp

using namespace cv;

void onMouse(int event, int x ,int y, int flags,void* param);

int main(int argc,char** argv){
   VideoCapture cap(-1);
   Mat frame;
   Mat grey;
   double width;
   double height;

   namedWindow("WebCam",1);
   cvSetMouseCallback("WebCam",onMouse,NULL);
   width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
   height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
   grey = Mat(height,width,CV_8UC1);
   while(1){
              cap >> frame;
              printf("frame.depth %d\n",frame.depth()); // it will return 0;
              printf("frame.type %d\n",frame.type()); //  it will return 16;
              preprocessing(frame,grey); // pass to share lib
              imshow("WebCam",grey);
              if(cvWaitKey(1)>=0){
                        break;
            }
    }
    cvDestroyWindow("WebCam");
    return 0;
}

Here is the Source for preprocess.cpp , it is complied to libpreprocess.so

void preprocessing(const Mat &imgSrc,Mat &resultImg)
{
    printf("imgSrc.depth %d\n",imgSrc.depth()); // here, it will return 1;
    printf("imgSrc.type %d\n",imgSrc.type()); // here it will return 1;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-02-21 10:43:01 -0600

unxnut gravatar image

CV_8U is a defined constant. If you try to print it, you will see that you do not get the string but a number. So, what you are getting is fine.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-02-21 10:05:49 -0600

Seen: 459 times

Last updated: Feb 21 '14