Reputation: 804
I've just started working with openCV in iOS, and I want to extract the ROI (Region Of Interest) from a particular cv::Mat.
This is my current code:
- (UIImage*)test {
UIImage* img = [UIImage imageNamed:@"unnamed"];
cv::Mat mat1;
UIImageToMat(img, mat1);
cv::Rect rect = cv::Rect(175, 219, 130, 50);
cv::Mat mat2 = mat1(rect);
return MatToUIImage(mat2);
}
However the result is not as I expected:
Here's the original image, in which I want to extract the bottom texts:
And here's the result:
I'm absolutely new to OpenCV, so I don't have any idea what causes this. Can someone help please?
Upvotes: 0
Views: 497
Reputation: 3550
i extracted the ROI with the code below. but i am not sure if MatToUIImage(mat2);
will work maybe you need to MatToUIImage(mat2.clone());
cv::Mat mat1 = imread("e:/test/rSfOy.jpg");
cv::Rect rect = cv::Rect(310, 420, 330, 110);
cv::Mat mat2 = mat1(rect);
imshow("rect", mat2);
Upvotes: 2