0

I have a simple Python script to take photos using laptop camera based on this post.

In particular, the user can exit the program by pressing ESC. Below is part of the script

# cv2 is OpenCV module
key = cv2.waitKey(1)

# ESC is pressed
if k % 256 == 27:
    print("ESC is pressed, exit ...")
    break

While everything works fine. But when the keyboard is changed to other input (e.g. Russian, Chinese), pressing any keys (Here, any means A,B,C,...,Z key) while the video is streaming terminates the program with the following error prints out.

ASSERT: "false" in file qasciikey.cpp, line 501
Abort trap: 6

This error is not found when using English / French / German keyboard.

How can I handle this problem properly in my Python script? Thanks

K_inverse
  • 357
  • 3
  • 16
  • If you google search "qasciikey.cpp" you will find many threads reporting this error. Have you tried any solutions those may suggest? Can you update your post with any suggestions you've tried? Really, OpenCV is not meant as an interface library and it's better to use things like `imshow()` only as debugging tools, and instead use other libraries to properly display and interact with users. Either way, there might be a fix for this particular issue, so feel free to continue searching. But just as a note to keep in mind. – alkasm Feb 20 '19 at 01:14

1 Answers1

0

looks like opencv waitKey not works with unicode characters. you can try diffrent methods if you using windows you can try get chars with pywin32

import win32api
if win32api.GetAsyncKeyState(0x0000001B): #0x1B 0x001B
    print("ESC is pressed, exit ...")
    break

or youcan use digit buttons for breaking loop:

if cv2.waitKey(25)==0x30: #digit zero 0x0030 0x00000030
    print("num 0 is pressed, exit ...")
    break