I am trying to convert rectengle image to bigger square with 17 padding. following is my code. but that is not working

asked 2019-07-20 11:38:29 -0600

updated 2019-07-20 21:19:01 -0600

supra56 gravatar image

Code:

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

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

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

        cv::Mat  resizeImage = cv::Mat(size+34,size+34, croppedImage.type(),new cv::Scalar(0,0,0,255));
        if (offset_width > 0) {
            cv::Range rowRange = cv::Range(0, roiF.height); //select maximum allowed cols
            cv::Range rowDestRange = cv::Range(17, roiF.height + 17);
            croppedImage.operator()(rowRange, cv::Range(0, roiF.width)).copyTo(resizeImage.operator()(rowDestRange,  cv::Range(offset_width, offset_width + roiF.width)));
        } else if (offset_height > 0) {
            cv::Range colRange =cv::Range(0, roiF.width); //select maximum allowed cols(*roiF).height
            cv::Range colDestRange = cv::Range(17, roiF.width + 17);
            croppedImage.operator()(cv::Range(0, roiF.height), colRange).copyTo(resizeImage.operator()(cv::Range(offset_height, offset_height + roiF.height), colDestRange));

        }
        return [OpenCVWrapper UIImageFromCVMat:resizeImage];
edit retag flag offensive close merge delete