You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// [x] Check with only opencv 331 compiled in 32 bits (x86) with msvc15 using Visual Studio Community 2017 on Windows 10 and linked through CMake- passed
120
+
// [x] Check with opencv 331 and openjpeg 230 both compiled in 32 bits (x86) with msvc12 using Visual Studio Community 2017 on Windows 10 and both linked through CMake - passed
121
+
// - Needed to modify the macro in the target_link_libraries instruction in CMakeFile from ${OPENJPEG_LIBRARIES} to path on disk
122
+
// (akka : "${CMAKE_CURRENT_SOURCE_DIR}/../redistributables/ojpg230/msvc2015_${EX_PLATFORM_NAME}/Release/*.lib") to compile
123
+
// - Needed to modify the macro in the include_directories instruction in CMakeFiles from ${OPENJPEG_BINARY_DIR} to path on disk
124
+
// (akka : "D:/lib/openjpeg/build86/src/lib/" ; also included "D:/lib/openjpeg/build86/src/bin/") - did the same with ${OPENJPEG_SOURCE_DIR}
opj_setup_decoder(mopj_codec, mparameters); /* init the decoder */
142
+
opj_codec_set_threads(mopj_codec, 4); /* tell the decoder to work on 4 threads */
143
+
144
+
/* Decode an image with .jp2 format */
145
+
opj_image_t* mopj_img = NULL; /* output image */
146
+
if (!opj_read_header(mopj_stream_fname, mopj_codec, &mopj_img)) /* you need to read the header before decoding */
147
+
returnerror_message("Unable to read_header in main.");
148
+
if (!opj_decode(mopj_codec, mopj_stream_fname, mopj_img)) /* decoding */
149
+
returnerror_message("Unable to decode in main.");
150
+
if (DEBUG) debug_messages_opj_img(mopj_img);
151
+
152
+
/* Copy decoded data in cv::Mat using pointers arithmetics - note that we are copying the data to avoid segfaults */
153
+
/* NB : as this is a minimal example, we assume that the .jp2 file represents a grayscale image - a bit more work would be involved to handle multichannels images */
154
+
int width = mopj_img->x1;
155
+
int height = mopj_img->y1;
156
+
int channels = mopj_img->numcomps;
157
+
opcv_output = cv::Mat(cv::Size(width, height), CV_8UC1); /* latter, we will need to cast OPJ_INT32 data to uchar */
158
+
for(int channel = 0; channel < channels; channel++) /* iterate through the image pixels stored in the components data of an opj_image pointer */
159
+
for (int col = 0; col < width; col++)
160
+
for (int row = 0; row < height; row++)
161
+
opcv_output.at<uchar>(cv::Point(col, row)) = (uchar)*(mopj_img->comps->data++); /* we assume file is continuous on memory adress ; plus be aware of the cast to uchar */
0 commit comments