Skip to content

Fix cvSaveImage( ) function bug#19203

Merged
alalek merged 5 commits intoopencv:3.4from
zchrissirhcz:fix-cvSaveImage
Dec 24, 2020
Merged

Fix cvSaveImage( ) function bug#19203
alalek merged 5 commits intoopencv:3.4from
zchrissirhcz:fix-cvSaveImage

Conversation

@zchrissirhcz
Copy link
Copy Markdown
Contributor

@zchrissirhcz zchrissirhcz commented Dec 23, 2020

Hi, OpenCV Team

This PR tries to fix #12818 on branch 3.4.

Though labled as won't fix in existing issues, there are still some programs using cvSaveImage( ). I just happen to migrate a project with many OpenCV C API calls to C++ API calls, comparing two implementations results, and encounter opencv 3.4 latest version (3.4.13)'s cvSaveImage( ) still crash on Windows platform. Thus I would like to share my solution.

Pull Request Readiness Checklist

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

Apart from this PR's fix method, people could also write a simple function as alternative to the bug cvSaveImage:

void mySaveImage(const char* filename, IplImage* dst)
{
    cv::Mat img = cv::cvarrToMat(dst);
    cv::imwrite(filename, img);
}

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me.

Please note, that legacy C-API has zero test coverage, so we are not able to test this code. Also this is why regression in this function appears here (and lives here for 2+ years).

P.S. There are some C API tests are on 2.4 branch (EOL).

@alalek alalek merged commit 6e1da2e into opencv:3.4 Dec 24, 2020
@alalek alalek mentioned this pull request Apr 9, 2021
@zchrissirhcz zchrissirhcz deleted the fix-cvSaveImage branch November 12, 2021 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opencv 3.4.3 can't use cvsaveimage API

3 participants