0

There is a closed issue in openCV:

https://github.com/skvark/opencv-python/issues/134

that i want to work around in the https://github.com/WolfgangFahl/play-chess-with-a-webcam application.

e.g. when running:

scripts/runweb --detector=simple8x8 --autowarp --debug --input testMedia/scholarsmate.avi 

this crash will happen.

In this example the webgui mode of the application will be called which uses the same videoanalyze class as the command line version:

scripts/runweb --detector=simple8x8 --autowarp --debug --input testMedia/scholarsmate.avi 

which runs fine. The crucial call is in the video class according to the bug the showImage method needs to check if we are on the main thread.

How could i check whether on the main thread and then avoid the cv2.imshow command?

There is an answer for java but i don't know how to do this in python...

# show the image with the given title
def showImage(self, image, title, keyCheck=True, keyWait=5):
    cv2.imshow(title, image)
    if keyCheck:
        return not cv2.waitKey(keyWait) & 0xFF == ord('q')
    else:
        return True
Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
  • IMHO this is more of a design issue. First of all `showImage` shouldn't be a member of `Video` class -- it has nothing to do with "Video handling" (separation of responsibilities), doesn't even use any member variables. Then abstract the UI output, and provide an instance of appropriate derived class to the processing code. – Dan Mašek Dec 17 '19 at 17:55
  • see https://stackoverflow.com/questions/49096804/cv2-image-show-doesnt-work-when-multithreading – Wolfgang Fahl Dec 17 '19 at 20:46
  • @DanMašek - thank you for your comment. You might want to join https://gitter.im/play-chess-with-a-webcam/community or https://github.com/WolfgangFahl/play-chess-with-a-webcam/issues/23 for design discussions. "Video" might indeed have to be renamed to Vision as in https://opencv.org/about/ - it's for encapsulating the opencv library and to be able to hide the details or in this case - work around an issue of a specific all. – Wolfgang Fahl Dec 17 '19 at 20:49
  • would https://stackoverflow.com/a/47148962/1497139 be the answer and my question is more or less a duplicate? – Wolfgang Fahl Dec 17 '19 at 20:53
  • Yeah, [this](https://stackoverflow.com/a/23207116/3962537) one seems to answer your actual question quite well, and it could easily be considered a duplicate. However, while this might solve your immediate issue, I'd say it's not the cleanest solution. | Rather than renaming the `Video` class, you should split it up into smaller pieces, each with a narrow focus. I'll check out the repository, but while I do know a bit about opencv, multithreading and GUI development, my chess knowledge is quite lacking ;) – Dan Mašek Dec 17 '19 at 21:08

0 Answers0