Copy cropped image

asked 2015-11-02 03:19:25 -0500

Pellaeon gravatar image


I undistort an image with opencv. After this I want to remove the black regions in the periphery which are caused by the undistortion. Therefore I define a border which I want to remove.

    const int border_width  = 10;
    const int croppedWidth  = resolution.first - 2 * border_width;
    const int croppedHeight = croppedWidth  * resolution.second / resolution.first;
    const int border_height = (resolution.second - croppedHeight) / 2;

    cv::Mat srcImg(resolution.second, resolution.first, cvFormat, const_cast<unsigned char*>(pImg));
    auto imgRoi = srcImg(cv::Rect(border_width, border_height, croppedWidth, croppedHeight));

    pImg       = reinterpret_cast<unsigned char*>(m_croppedRenderImg->data);
    resolution = std::make_pair(croppedWidth, croppedHeight);

Because I need the image as raw pointer as input for a texture in ogre I want the image to be on one memory block. Therefore I can't use the imgRoi. I tried to get this via "copyTo". My problem is that the result image is wrong. It looks shifted.

So, what is wrong with my code?

Best regards


edit retag flag offensive close merge delete


So you are only modifying m_croppedRenderImg->data? What about it's dimensions? I don't know your reasons to do so much pointer fiddling, you know about OpenCV's memory management already being quite efficient right?

boaz001 gravatar imageboaz001 ( 2015-11-02 04:40:28 -0500 )edit