OpenCV build error - opencv_annotation - openjpeg issue?

I’m struggling to get openCV to build and I have a feeling it has to do with OpenJPEG not being installed correctly.

I’ve essentially used a slightly modified version of this script to install 4.5.1:

My exact cmake command is:
cmake -D WITH_CUDA=ON -D WITH_CUDNN=ON -D CUDA_ARCH_BIN=“5.0” -D CUDA_ARCH_PTX="" -D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_EXTRA_MODULES_PATH=…/…/opencv_contrib-${version}/modules -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON -D BUILD_opencv_python2=ON -D BUILD_opencv_python3=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_JPEG=ON …

I’m also using anaconda as my python which I understand might be causing issues, but I can’t seem to pinpoint how. I’m also running in WSL but I don’t see how that would cause this issue. CUDA works fine and I can compile darknet great, just need to get opencv to install which I didn’t think would take this long. If I can’t get it to work I might just dual-boot.

Output:

[ 56%] Building CXX object modules/bioinspired/CMakeFiles/opencv_bioinspired.dir/src/retinafilter.cpp.o
[ 56%] Building CXX object modules/bioinspired/CMakeFiles/opencv_bioinspired.dir/src/transientareassegmentationmodule.cpp.o
/usr/bin/ld: …/…/lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_stream_default_create' /usr/bin/ld: ../../lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_create_compress’
/usr/bin/ld: …/…/lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_setup_decoder' /usr/bin/ld: ../../lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_destroy_codec’
/usr/bin/ld: …/…/lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_read_header' /usr/bin/ld: ../../lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_image_destroy’
/usr/bin/ld: …/…/lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_end_compress' /usr/bin/ld: ../../lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_stream_destroy’
/usr/bin/ld: …/…/lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_image_create' /usr/bin/ld: ../../lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_stream_set_skip_function’
/usr/bin/ld: …/…/lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_encode' /usr/bin/ld: ../../lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_stream_set_read_function’
/usr/bin/ld: …/…/lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_set_error_handler' /usr/bin/ld: ../../lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_set_warning_handler’
/usr/bin/ld: …/…/lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_stream_set_user_data' /usr/bin/ld: ../../lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_start_compress’
/usr/bin/ld: …/…/lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_stream_set_user_data_length' /usr/bin/ld: ../../lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_decode’
/usr/bin/ld: …/…/lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_set_default_decoder_parameters' /usr/bin/ld: ../../lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_create_decompress’
/usr/bin/ld: …/…/lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_setup_encoder' /usr/bin/ld: ../../lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_stream_set_seek_function’
/usr/bin/ld: …/…/lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_set_default_encoder_parameters' /usr/bin/ld: ../../lib/libopencv_imgcodecs.so.4.5.1: undefined reference to opj_stream_create_default_file_stream’
collect2: error: ld returned 1 exit status
make[2]: *** [apps/annotation/CMakeFiles/opencv_annotation.dir/build.make:92: bin/opencv_annotation] Error 1
make[1]: *** [CMakeFiles/Makefile2:6729: apps/annotation/CMakeFiles/opencv_annotation.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs…

Here is the full output:

Anyone encounter this issue before?

EDIT: now trying to build with BUILD_opencv_python2=OFF as maybe something silly I forgot was in there. but I’m pretty sure this issue was there when I followed this other tutorial earlier on

EDIT2: Yup, same output with opencv_waldboost_detector now, also unassigned references and the same ones

I might have managed to fix this issue by uninstalling openjp2 and updating it on anaconda using:

conda install -c conda-forge openjpeg

This is probably due to anaconda being first in my path environment variable, but I can’t confirm or be sure whether this is actually what fixed it.

Currently sitting at 95% so hopefully didn’t jinx it by posting this.

1 Like