Ask Your Question

Revision history [back]

copyTo with () operator is not working on IOS

I am getting Thread 1: Heap buffer overflow. when i run following code. Actually I want to convert rectangle image to bigger square image and image should be centred.

It generates error on copyto function when there is range provided.

   cv::Mat croppedImage;
   cv::Mat(orig_image, roiF).copyTo(croppedImage);
   cv::Mat(orig_image,roiF).clone();

    int size = roiF.height > roiF.width ? roiF.height : roiF.width;

    int offset_height = ((size) / 2 - (roiF.height) / 2);
    int offset_width = ((size ) / 2 - (roiF.width) / 2);

    cv::Mat  resizeImage = cv::Mat(size, size , croppedImage.type(),new cv::Scalar(0,0,0,255));
    if (offset_width > 0) {
        cv::Range colSrcRange = cv::Range(0, roiF.width);
        cv::Range rowSrcRange = cv::Range(0, roiF.height); //select maximum allowed cols
        cv::Range colDestRange = cv::Range(offset_width, offset_width + roiF.width);
        cv::Range rowDestRange = cv::Range(0, roiF.height + 0);
        croppedImage(rowSrcRange, colSrcRange).copyTo(resizeImage(rowDestRange,  colDestRange));
    } else if (offset_height > 0) {
        cv::Range colSrcRange =cv::Range(0, roiF.width); //select maximum allowed cols(*roiF).height
        cv::Range rowSrcRange =cv::Range(0, roiF.height);
        cv::Range colDestRange = cv::Range(0, roiF.width + 0);
        cv::Range rowDestRange = cv::Range(offset_height, offset_height + roiF.height);
        croppedImage(rowSrcRange, colSrcRange).copyTo(resizeImage(rowDestRange,  colDestRange));
    }
    return [OpenCVWrapper UIImageFromCVMat:resizeImage];
click to hide/show revision 2
retagged

updated 2019-07-23 12:25:31 -0600

berak gravatar image

copyTo with () operator is not working on IOS

I am getting Thread 1: Heap buffer overflow. when i run following code. Actually I want to convert rectangle image to bigger square image and image should be centred.

It generates error on copyto function when there is range provided.

   cv::Mat croppedImage;
   cv::Mat(orig_image, roiF).copyTo(croppedImage);
   cv::Mat(orig_image,roiF).clone();

    int size = roiF.height > roiF.width ? roiF.height : roiF.width;

    int offset_height = ((size) / 2 - (roiF.height) / 2);
    int offset_width = ((size ) / 2 - (roiF.width) / 2);

    cv::Mat  resizeImage = cv::Mat(size, size , croppedImage.type(),new cv::Scalar(0,0,0,255));
    if (offset_width > 0) {
        cv::Range colSrcRange = cv::Range(0, roiF.width);
        cv::Range rowSrcRange = cv::Range(0, roiF.height); //select maximum allowed cols
        cv::Range colDestRange = cv::Range(offset_width, offset_width + roiF.width);
        cv::Range rowDestRange = cv::Range(0, roiF.height + 0);
        croppedImage(rowSrcRange, colSrcRange).copyTo(resizeImage(rowDestRange,  colDestRange));
    } else if (offset_height > 0) {
        cv::Range colSrcRange =cv::Range(0, roiF.width); //select maximum allowed cols(*roiF).height
        cv::Range rowSrcRange =cv::Range(0, roiF.height);
        cv::Range colDestRange = cv::Range(0, roiF.width + 0);
        cv::Range rowDestRange = cv::Range(offset_height, offset_height + roiF.height);
        croppedImage(rowSrcRange, colSrcRange).copyTo(resizeImage(rowDestRange,  colDestRange));
    }
    return [OpenCVWrapper UIImageFromCVMat:resizeImage];