-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
Open
Labels
category: 3rdpartycategory: highgui-guiplatform: ios/osxquestion (invalid tracker)ask questions and other "no action" items here: https://forum.opencv.orgask questions and other "no action" items here: https://forum.opencv.org
Description
System Information
OpenCV Python Version: 4.6.0.66
Operating System / Platform: macOS Monterey Version 12.6
Chip: Apple M1 Max
Python Version: 3.10.6
Also using NumPy for storing image data
numpy 1.23.2
Detailed description
When using cv.imshow() to display an image it works fine when using a single thread. When one thread invokes a second thread to show the image the following error occurs:
Exception in thread Thread-2:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/Users/spock/workspace/enterprise/src/opencvbug.py", line 28, in run
self.render_callback(random_image)
File "/Users/spock/workspace/enterprise/src/opencvbug.py", line 15, in render_image
cv2.imshow('CV2 C++ Bug', image)
cv2.error: Unknown C++ exception from OpenCV code
Assertion failed: (NSViewIsCurrentlyBuildingLayerTreeForDisplay() != currentlyBuildingLayerTree), function
NSViewSetCurrentlyBuildingLayerTreeForDisplay, file NSView.m, line 13477.
This steps to reproduce below demonstrate the code working from a main method and then demonstrates the same code failing when it's threaded.
Steps to reproduce
import cv2
import numpy as np
import threading
import time
class Renderer(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def render_image(self, image):
print('Showing image in renderer thread... kaboom!')
cv2.imshow('CV2 C++ Bug', image)
cv2.waitKey(1)
class ImageStream(threading.Thread):
def __init__(self, render_callback):
threading.Thread.__init__(self)
self.render_callback = render_callback
def run(self):
for i in range(7):
random_image = np.random.randint(255, size=(420, 666, 3),dtype=np.uint8)
self.render_callback(random_image)
time.sleep(1)
if __name__ == '__main__':
print('Showing random image in main thread ...')
for i in range(7):
rand_img = np.random.randint(255, size=(420, 666, 3),dtype=np.uint8)
cv2.imshow('CV2 Single Thread Works', rand_img)
cv2.waitKey(1)
time.sleep(1)
cv2.destroyAllWindows()
render_thread = Renderer()
render_thread.start()
im_stream_thread = ImageStream(render_callback=render_thread.render_image)
im_stream_thread.start()
im_stream_thread.join()
render_thread.join()
cv2.destroyAllWindows()
Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files (videos, images, onnx, etc)
abedputra, kingwingfly, thelfensdrfer, sebos123, dogukanburda and 2 more
Metadata
Metadata
Assignees
Labels
category: 3rdpartycategory: highgui-guiplatform: ios/osxquestion (invalid tracker)ask questions and other "no action" items here: https://forum.opencv.orgask questions and other "no action" items here: https://forum.opencv.org