Install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvWaitKey'

iam using pytorch igpu docker for my project nvcr.io/nvidia/pytorch:24.05-py3-igpu
after install opencv-python==4.8.0.74
when iam running a sample project in opencv iam getting an error like
root@IS23JO01001:/workspace# python3 test_cam.py
Traceback (most recent call last):
File “/workspace/test_cam.py”, line 22, in
if cv2.waitKey(1) & 0xFF == ord(‘q’):
cv2.error: OpenCV(4.7.0) /opencv-4.7.0/modules/highgui/src/window.cpp:1338: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function ‘cvWaitKey’

test_cam.py is just a sample opencv program
import cv2

cap1 = cv2.VideoCapture(f’v4l2src device=/dev/video0 ! video/x-raw, width=640, height=360 ! videoconvert ! appsink’, cv2.CAP_GSTREAMER)

cap2 = cv2.VideoCapture(f’v4l2src device=/dev/video2 ! video/x-raw, width=640, height=360 ! videoconvert ! appsink’, cv2.CAP_GSTREAMER)

while True:
# Read frames from both cameras
ret1, frame1 = cap1.read()
ret2, frame2 = cap2.read()

if ret1:
    cv2.imshow('Camera 1', frame1)
    
if ret2:
    cv2.imshow('Camera 2', frame2)

if cv2.waitKey(1) & 0xFF == ord('q'):
    break

cap1.release()
cap2.release()
cv2.destroyAllWindows()

how can i fix this error please help me

i tried install apt-get install libgtk2.0-dev pkg-config still same error
iam using currently opencv-python==4.8.0.74

Hi,

Please try the below command:

Thanks.

sir but now iam getting a other error
Traceback (most recent call last):
File “/workspace/test_cam.py”, line 18, in
cv2.imshow(‘Camera 1’, frame1)
cv2.error: OpenCV(4.7.0) /opencv-4.7.0/modules/highgui/src/window.cpp:1272: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage

how i should fix this
this is opencv-python==4.8.0.74

Hi,

Please give the above comment a try.
Thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.