简体   繁体   中英

OpenCV IOS Resize a Mat

I am trying to resize a Mat on the fly which I am overlaying on to another image. The image is stored on the IOS device in the Assets.xcassets folder and I am passing it to my function then using UIImageToMat to convert it to a cv::Mat.

As a test I want to be able to resize it to make it half the size, but I am running into problems.

When I tried overlay->resize(overlay->rows/2); The result overlay just shows the top half of what it was.

Then when I tried cvResize(overlay, destPointer, CV_INTER_LINEAR); I get the error:

error: (-5) Unknown array type in function cvarrToMat

C++:

cv::Point center;
int radius;
double NewRadius;

cv::Mat originphoto;
UIImageToMat(overlay, originphoto, 1);
cv::Mat *overlay = &originphoto;

center.x = cv::saturate_cast<int>((r->x + r->width*0.5) - overlay->size().width*0.5);
center.y = cv::saturate_cast<int>((r->y + r->height*0.5 - overlay->size().height*0.5));
radius = cv::saturate_cast<int>((r->width + r->height) / 2);
printf("%d",radius);
NewRadius = radius/1;
cv::Mat destination(overlay->rows/2, overlay->cols/2, 1);
cv::Mat *destPointer = &destination;

cvResize(overlay, destPointer, CV_INTER_LINEAR);

overlay = destPointer;

Any help here would be greatly appreciated, still very new to image processing and not sure how to deal with these cv::Mats since they are matrices.

Got it working using:

cv::resize(*overlay, destination, cv::Size(), 0.5, 0.5);

If anyone else runs into this problem, there you go :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM