Does matlab supports imgcodes of openCV

12 Ansichten (letzte 30 Tage)
Manmeet
Manmeet am 18 Jan. 2025
Beantwortet: Broy am 4 Sep. 2025 um 6:57
Iam trying to use cv2.imwrite in jpeg format for which imagecodes of opencv is required. Ultimately want to use the C++ code using openCV for convertion to matlab readable format using mexOpenCV function.
I have installed "computer vision toolbox interface for OpenCV in Matlab". But the conversion throws error because when i check the precences of imgcodes.hpp inside opencv2 folder its not present.
The automatically generated file opencv_modules.hpp also does not list down imgcodecs

Antworten (1)

Broy
Broy am 4 Sep. 2025 um 6:57
Hi Manmeet,
It looks like you are trying to use OpenCV’s cv::imwrite (via the Computer Vision Toolbox Interface for OpenCV in MATLAB) to save an image in JPEG format. The issue arises because the OpenCV version included with MATLAB does not have the imgcodecs module, which is required for functions like imwrite. That’s why you don’t see imgcodecs.hpp or the module listed in opencv_modules.hpp.
To resolve this, you have two potential options:
1. Simplest: Use MATLAB’s own functions for image I/O.
MATLAB already supports saving images in JPEG directly. For example:
img = imread('sample_img.png');
imwrite(img, 'output.jpg');
This avoids the need for OpenCV completely.
2. If you specifically need OpenCV’s imwrite inside a MEX function:
You will need a full OpenCV build that includes the imgcodecs module. MATLAB’s packaged OpenCV does not include it. In that case, you’d have to install OpenCV separately and link your MEX code against it.
Helpful Documentations you can refer to:
Hope this helps.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by