Repository navigation
Description
Description
Hello,
I am working on a project that uses both ITK and OpenCV. My code runs normally without any errors. However, it does not terminate even if the main() function reaches the return statement (I have to manually force-stop it each time). I noticed that this problem occurs when in a specific combination of functions is used from each library (see working example). The problem appears both in Release and Debug mode. In addition, I can see in Visual Studio that the memory is not released. Thanks!
Steps to Reproduce
I can reproduce the issue both running the executable from inside the Visual Studio and the command line. A minimal working example showing the issue is the following:
#include <string>
#include "itkImageFileWriter.h"
#include <opencv2/opencv.hpp>
int main( int argc, char* argv[] ) {
typedef itk::Image< float, 2u > ImageType;
typedef itk::ImageFileWriter< ImageType > ResultImageWriterType;
typedef ResultImageWriterType::Pointer ResultImageWriterPointer;
const std::string filename = "test.jpg";
// If you comment any of these two lines, the problem disappears
cv::Mat frame0 = cv::imread(filename, cv::IMREAD_GRAYSCALE);
ResultImageWriterPointer outputImageWriter = ResultImageWriterType::New();
return 0;
}
Expected behavior
The executable should stop running.
Actual behavior
The executable seems to continue running.
Reproducibility
It occurs every time.
Versions
ITK 5.0.1
OpenCV 4.2.0
Environment
CMake 3.16.2
Visual Studio 2019 with MSVC compiler x64
Windows 10 - 64bit
Additional Information
The CMakeLists.txt:
cmake_minimum_required( VERSION 3.16.2)
project( bugITKOpenCV )
set(CMAKE_CXX_STANDARD 11)
list(APPEND CMAKE_PREFIX_PATH "C:/opencv/build" "C:/itk5")
# ITK
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
# OPENCV
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
# Add the executables
add_executable(bugTest bugReplicate.cxx)
target_link_libraries(bugTest ${ITK_LIBRARIES})
target_link_libraries(bugTest ${OpenCV_LIBS})
Activity
dzenanz commentedon Jan 30, 2020
I could not reproduce this
I used OpenCV3.3 (built using VS2015), recent master of ITK with static libraries, CMake 3.16.3, VS2019 x64, Windows 10, using a debug build. Edit: no problem with RelWithDebInfo build either.
ntatsisk commentedon Jan 31, 2020
Thank you @dzenanz for taking the time to try reproducing the error. Unfortunately, it persists for me.
I also tried using the function exit(), which seems that it fixes the issue for this working example but when I try to do the same in my original code, it doesn't fix it. Both cases in Release mode.
Any hint would be highly appreciated. Otherwise, I will continue force-stopping by program and maybe try on a different computer later on.
dzenanz commentedon Feb 3, 2020
Did you solve the issue? What was the problem?
ntatsisk commentedon Feb 6, 2020
Hey @dzenanz, no I haven't solved the problem. In fact, quite the opposite. I realized that when I run the executable of my original code, it has different behavior when I use the command line than when I use the Visual Studio IDE.
In the command line, the program cannot even return from the last function called which means that it cannot actually complete the entire execution. This issue does not happen when using the VS (Although, it still does not return from the main() function = I need to force-stop it).
Since you couldn't reproduce the problem, I closed the issue but maybe that was a mistake :D
COMP: Update to openjpeg v2.5.4 (2025-09-20)
COMP: Update to openjpeg v2.5.4 (2025-09-20)
COMP: Update to openjpeg v2.5.4 (2025-09-20)