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); mIntermedia
Solution 1:
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:
Matuncropped= getUncroppedImage();
Rectroi=newRect(x, y, width, height);
Matcropped=newMat(uncropped, roi);
Solution 2:
I have always done cropping this way:
Matimage= ...; // fill it however you want to
Mat crop(image, Rect(0, 0, image.cols, image.rows / 2)); // NOTE: this will only give you a reference to the ROI of the original data// if you want a copy of the crop do this:Matoutput= crop.clone();
Hope that helps!
Solution 3:
Seems cv::getRectSubPix does what you want. Plus you don't have to allocate more space than you need. Also it does necessary interpolations if the cropped area is not aligned over an exact pixel.
This should do what you want. Input type will be the output type.
Mat dst;
getRectSubPix(src, Size(src.rows()/2,src.cols()), Point2f(src.rows()/4, src.cols()/2), dst);
Post a Comment for "Cropping Image In Android Using Opencv"