-
Notifications
You must be signed in to change notification settings - Fork 826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cv.imshow not working in Mac #412
Comments
What's your os? If you are not running on windows, did you compile OpenCV with libgtk or similar on Mac? Not sure why it simply hangs on your machine. |
Same here on MacOS 10.13.6 (17G65) after installing with |
Same here, I was trying to run the I am on MacOS High Sierra. MBP2017 15", nodejs 8.11.x, typescript 3.x, ts-node 7.0.x and vscode 1.28.1. Thanks. |
I can confirm it's a MacOS bug. The event loop will block entirely until the spawned image process (or window, unsure how it's created) by imshowWait() receives user input, upon receiving input the event loop continues and everything resumes. Likely an issue upstream with the imshowWait() implementation. |
Did you find a workaround? I can't get cv.imshow() to work at all (no window appears). cv.imshowWait() displays a window with the image but of course it needs input before it will release the process. |
BTW, I think I have a workaround. I added cc::waitKey(1) after calling cv::imshow(). This appears to allow the window to show and be updated, but does not wait for a keypress: The source I modified is in node_modules/opencv4nodejs/cc/modules/io/io.cc
|
opencv (or better highgui) does all window handling in cv::waitKey. So waitKey is necessary to get your windows to do anything. |
@Garfonso Odd that none of the opencv examples indicated you need to call waitKey after imshow. Should the node binding require waitKey when other bindings don't? |
@jmbldwn
The examples for opencv4nodejs usually call imshowWait which is a opencv4nodejs specific method and calls cv::waitKey(), as you can see here: Line 95 in 02be3b6
it calls cv::waitKey without an argument, so waitKey will wait indefinitely for a key press. Usually that should make the window work fine. Of course the JS thread will be blocked until you press a key on the highgui window. Also I do not know about what other bindings you are talking, tbh. But maybe they do not use opencv highgui but another UI? |
I am sorry, but I am not able to grasp the concept. How am I actually supposed to call the waitKey function then? I am trying to play a video file using Electron js. I am using imshow to display the video in the window, and only one frame renders; until and unless I press any key on the keyboard. Then it would render the second frame and so on.. code for reference. (Does electron render in a highgui window? @Garfonso ) while(totalNumberofFrames) {
} |
I don't know what electron js is, but your code does look a lot like highgui. Just add a parameter to the cv.waitKey(). cv.waitKey(n) waits n milliseconds for a keypress, so it returns after a key pressed or at least after n milliseconds. If the parameter is omitted, then it only returns when a key is pressed. |
God damn, thanks! The problem was I only tried 0 as the 'n' value, just like in Python, and for some reason it does not work in opencv4nodejs the same way. It just stops at the first frame. I changed the n value to 1, now it renders all the frames. Thanks for the heads up! @Garfonso |
I'm hoping I can get this to work for me, I'm soooo close. I'm having the same/similar issue. Builds just fine and runs non-UI cv functions just fine. But when I use cv imshow it fails with the following. This is pretty obscure, I only found this error in a few items after Google searching. MacOS 10.14.6. opencv4nodejs 5.5.0. I used the (npm install opencv-build) to build. Any thoughts would be greatly appreciated. Also, the xmodules property on cv wasn't there so I had to change it to modules. Thanks in advance for anyone willing to give this a look.
And here is the test I was running...
|
I am also facing the issue above with the exact same NSApplication error on macOS 10.15.5 |
HI:
Thank you binding opencv for node!
I try the code in Mac,but the "cv.imshowWait" don't display the image,just hold the process.
The text was updated successfully, but these errors were encountered: