Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cropping image in Android using opencv

I am using OpenCV 2.3.1 in Android. I need to crop the image into half. What I am doing is:

    Mat mIntermediateMat2 = new Mat(frame_height,frame_width,rgba.type);
    mIntermediateMat2 = rgba.clone();
    mIntermediateMat2 = mIntermediateMat2.rowRange(0,frame_height/2);

Will the third step do the job or I have to add something more? I saw Mat::operator() in opencv 2.3 documentation but unfortunately not able to find in the opencv Android package.

like image 813
akniazi Avatar asked Nov 03 '11 21:11

akniazi


1 Answers

There are a few constructors for the Mat class, one of which takes a Mat and an ROI (region of interest).

Here's how to do it in Android/Java:

Mat uncropped = getUncroppedImage();
Rect roi = new Rect(x, y, width, height);
Mat cropped = new Mat(uncropped, roi);
like image 162
Sam Uong Avatar answered Sep 18 '22 14:09

Sam Uong