There is an example program to test the opencv Python install which pops up a window displaying an image and writes the mouse pointer XY coordinates to the lower left hand corner of the window. Half of the coordinates fall outside of the window and the window is not resizeable. The same error occurs with the .cpp version.
The print statement does nothing. It does not show up on the GUI nor on the command shell stdout/stderr.
I built the cpp version from source from gethub opencv/opencv/archive/4.x zip by the instructions in docs.opencv.org 4.x/d7/d9f/tutorial_linux_install html
Python source collided with VLC player and wanted to downgrade ffmpeg, libavformat57 and ~30 other source modules. I installed with:
sudo pip3 install opencv-python
I wrote the “output.png” and it is identical to the input image.
The mouse pointer XY coordinates are not written over the image but rather to the window decoration below the image. I took a screenshot of original image in xv with the imread.py gui over it to show the window decoration below the image.
Where would the “WINDOW_NORMAL” flag be inserted into this code?
#!/usr/bin/python
import cv2 as cv
img = cv.imread("/home/brianp/bin/rad_weight.f.jpg")
cv.imshow("Brian's Python window", img)
#cv.imwrite("output.png", img)
k = cv.waitKey(0) # Wait for a keystroke in the window
I compiled the cpp version from latest code. It has exactly the same behavior and is running opencv 4.8.
Clicking the “X” icon in the upper left corner → more_actions → special_window_settings, the “window types” == “Normal Window”.
The exact same defect is shown in the CPP version compiled from opencv 4.8 source today.
I added this before the imread(). It had 3 effects; The window was shrunk to postage stamp size, the window was made resizeable (so the decoration at the bottom was expandable) and the coordinate writing was disabled.
#!/usr/bin/python
import cv2 as cv
img = cv.imread("/home/brianp/bin/rad_weight.f.jpg")
cv.namedWindow("Brian's Python window", cv.WINDOW_GUI_NORMAL)
cv.imshow("Brian's Python window", img)
#cv.imwrite("output.png", img)
k = cv.waitKey(0) # Wait for a keystroke in the window
OpenCV 4.8.0-dev is really broken compared to 4.5.5!
I altered the #include to point to 4.8 and altered the g++ to also point to 4.8. Then I verified the linking with ldd to show the libraries used like: libopencv_core.so.408 => /usr/local/lib64/libopencv_core.so.408 (-> libopencv_core.so.4.8.0)
Now, there is no decoration above or below and no XY coordinates are printed at all.
/*
g++-10 -L/usr/local/lib64 -I/usr/local/include/opencv4/opencv2 \
-lopencv_imgcodecs -lopencv_core -lopencv_highgui \
imread.cv.cpp -o imread
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib64
ldd imread | grep opencv
libopencv_core.so.408 =>
/usr/local/lib64/libopencv_core.so.408 (0x00007f73caf90000)
libopencv_highgui.so.408 =>
/usr/local/lib64/libopencv_highgui.so.408 (0x00007f73caf52000)
libopencv_imgcodecs.so.408 =>
/usr/local/lib64/libopencv_imgcodecs.so.408 (0x00007f73cbcdb000)
libopencv_imgproc.so.408 =>
/usr/local/lib64/libopencv_imgproc.so.408 (0x00007f73c8f3b000)
*/
#include <iostream>
// #include <opencv2/opencv.hpp>
#include "/usr/local/include/opencv4/opencv2/opencv.hpp"
using namespace cv;
using namespace std;
// Driver code
int main(int argc, char** argv) {
// Read the image file
Mat image = imread(argv[1]);
// Error Handling
if (image.empty()) {
cout << "Image File Not Found" << endl;
cin.get(); // wait for any key press
return -1;
}
// Show Image inside a window with the name provided
imshow("Brian's Image Window", image);
cout << getBuildInformation() << endl;
waitKey(0); // Wait for any keystroke
return 0;
}
The getBuildInfo() dump verifies the version:
General configuration for OpenCV 4.8.0-dev ====
They are all synonymous links of varying formats:
/usr/local/lib64/libopencv_core.so → libopencv_core.so.408 → libopencv_core.so.4.8.0
The Image is not truncated in 4.5 or 4.8. The XY coordinates written to the “shell” which was part of the gui window decorations above and below the jpg image. 4.5 shows whitespace above and below with the XY coordinates truncated in the bottom window and only whitespace in the top part. 4.8 shows no decorations at all, exactly the same thing that “xv” shows.
This is the code which was written half off of the gui in 4.5 and now is entirely off the window in 4.8.
# displaying the coordinates on the Shell
print(x, ' ', y)
On top is the 4.5 window showing the top half of the XY coords and the color. Below is the 4.8 behavior with no bottom decoration at all, just 100% image.
The behavior is different between opencv 4.5 and 4.8, 4.5 is half truncated whereas 4.8 is fully truncated.
The idea was to show the XY coordinates wrt/ the image on the gui window while the mouse was moved.
It does not appear to be so. The QT, the Suse and the application code are constant.
The defect varies with the opencv libraries linked to. Using opencv 4.5 truncates half of the XY coordinates. Linking to opencv 4.8 truncates the XY coordinates entirely.
The workaround is to open a file and write the XY data there as part of the mouseClick event handler.
All of the buttons in the buttonbar are hidden (invisible entirely) and appear only when moused over. None do anything except the save_as button.