maxruby / OpenCV.jl

The OpenCV (C++) interface for Julia
Other
104 stars 28 forks source link

closeWindows does not close window #19

Closed maxruby closed 7 years ago

maxruby commented 7 years ago

System: OSX 10.12.3 Julia: 0.6.0-pre.alpha.49, master/eca966c

Description:

In julia 0.5.0-dev the closeWindows() method used to function properly, i.e., upon pressing a key matching the code in the callback (e.g., 27), it would close the window displaying the image(s) immediately.

Currently, to close the image window, one must exit() the Julia REPL. In addition, the window continues to wait indefinitely in a callback loop (OSX loading icon is displayed).

This affects also imdisplay() which also wraps this method.

Reproduction:

filename = joinpath(Pkg.dir("OpenCV"), "./test/images/lena.png");
img = imread(filename)
namedWindow("Lena", WINDOW_AUTOSIZE)
imshow("Lena", img)
closeWindows(0,27,"Lena")   # waits until ESC key(27) press to close "Lena"
maxruby commented 7 years ago

This is not a bug with the OpenCV.jl implementation. closeWindow works fine when it is run inside a file script .jl from the bash terminal (not julia REPL terminal):

bash terminal:

julia /Users/Max/Desktop/test_opencv.jl

Test code as file in /Users/Max/Desktop/test_opencv.:

using OpenCV

# Image properties
width = cint(300)
height = cint(300)

# Color
R=cint(255)
G=cint(0)
B=cint(0)

cxx"""
void create_image_and_display(int width, int height, int B, int G, int R)
   {
   // Create a new image width x height, 8-bit unsigned RGB (BGR in OpenCV)
   cv::Mat img(width, height, CV_8UC3, cv::Scalar(B,G,R));  // Blue, Green, Red (0:255)

   // Create a new window named "Welcome"
   cv::namedWindow("Welcome", cv::WINDOW_AUTOSIZE);

   // Show the image in window
   cv::imshow("Welcome", img);

   // Writing a message to the REPL from Julia
   std::cout << "\nTo end this test, press any key" << std::endl;

   // Wait for key press
   cv::waitKey(0);

   // Destroy the window
   cv::destroyWindow("Welcome");

 }
"""

@cxx create_image_and_display(width, height, B, G, R)