# Python OpenCV IMSHOW error when running even when provided all parameters

**URL:** <https://forum.opencv.org/t/python-opencv-imshow-error-when-running-even-when-provided-all-parameters/18459>\
**Category:** Python\
**Tags:** highgui, programming\
**Created:** [August 8, 2024, 3:40pm UTC](https://forum.opencv.org/t/python-opencv-imshow-error-when-running-even-when-provided-all-parameters/18459 "2024-08-08T15:40:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sns123](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/sns123/32/10697_2.png) [@sns123](https://forum.opencv.org/u/sns123)\
**Post date:** [August 8, 2024, 3:40pm UTC](https://forum.opencv.org/t/python-opencv-imshow-error-when-running-even-when-provided-all-parameters/18459/1 "2024-08-08T15:40:06Z")

</div>

I am using OpenCV for my program but I am getting an error during the cv2.imshow command. My program is trying to process an MP4 video and crop the licence plates from the cars involved.

I am following [this tutorial](https://www.youtube.com/watch?v=fyJB1t0o0ms) for this purpose, and am on 30:02 time.

Here is my code:

```auto
from ultralytics import YOLO
import cv2
from sort.sort import *
import string
import easyocr

mot_tracker = Sort()
results = {}

coco_model = YOLO('yolov8n.pt')
license_plate_detector = YOLO('/home/pi/Desktop/license_plate_detector.pt')

cap = cv2.VideoCapture('/home/pi/Desktop/carvid.mp4')

# Initialize the OCR reader
reader = easyocr.Reader(['en'], gpu=False)

# Mapping dictionaries for character conversion
dict_char_to_int = {'O': '0',
                    'I': '1',
                    'J': '3',
                    'A': '4',
                    'G': '6',
                    'S': '5'}

dict_int_to_char = {'0': 'O',
                    '1': 'I',
                    '3': 'J',
                    '4': 'A',
                    '6': 'G',
                    '5': 'S'}

def get_car(license_plate, vehicle_track_ids):
    x1, y1, x2, y2, score, class_id = license_plate

    foundIt = False
    for j in range(len(vehicle_track_ids)):
        xcar1, ycar1, xcar2, ycar2, car_id = vehicle_track_ids[j]

        if x1 > xcar1 and y1 > ycar1 and x2 < xcar2 and y2 < ycar2:
            car_indx = j
            foundIt = True
            break

    if foundIt:
        return vehicle_track_ids[car_indx]

    return -1, -1, -1, -1, -1

ret = True
frame_nmr = -1

vehicles = [2, 3, 5, 7]

while ret:
	frame_nmr+=1
	ret,frame = cap.read()
	if ret and frame_nmr < 10:
		pass
		
		detections = coco_model(frame)[0]
		detections_ = []
		
		for detection in detections.boxes.data.tolist():
			x1, y1, x2, y2, score, class_id = detection
			
			if int(class_id) in vehicles:
				detections_.append([x1,y1,x2,y2,score])
		
		track_ids = mot_tracker.update(np.asarray(detections_))
		
		license_plates = license_plate_detector(frame)[0]
		for license_plate in license_plates.boxes.data.tolist():
			x1, y1, x2, y2, score, class_id = license_plate

			xcar1, ycar1, xcar2, ycar2, carid = get_car(license_plate, track_ids)
			
			license_plate_crop = frame[int(y1):int(y2), int(x1): int(x2), :]
			
			license_plate_crop_gray = cv2.cvtColor(license_plate_crop, cv2.COLOR_BGR2GRAY)
			_, license_plate_crop_thresh = cv2.threshold(license_plate_crop_gray, 64, 255, cv2.THRESH_BINARY_INV)
			
			cv2.imshow('original_crop', license_plate_crop)
			cv2.imshow('threshold', license_plate_crop_thresh)
			cv2.waitKey(0)

```

When running this, my output shows this:

```auto
Using CPU. Note: This module is much faster with a GPU.

0: 384x640 21 cars, 1 bus, 2 trucks, 483.8ms
Speed: 7.2ms preprocess, 483.8ms inference, 1.9ms postprocess per image at shape (1, 3, 384, 640)

0: 384x640 2 license_plates, 456.4ms
Speed: 5.9ms preprocess, 456.4ms inference, 0.9ms postprocess per image at shape (1, 3, 384, 640)
Traceback (most recent call last):
  File "/home/pi/yolotest.py", line 85, in <module>
    cv2.imshow('original_crop', license_plate_crop)
cv2.error: OpenCV(4.10.0) /io/opencv/modules/highgui/src/window.cpp:1301: 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'

```

Please help as I don’t get what this is asking me todo.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [August 8, 2024, 7:29pm UTC](https://forum.opencv.org/t/python-opencv-imshow-error-when-running-even-when-provided-all-parameters/18459/2 "2024-08-08T19:29:24Z")

</div>

you should contact the author of the video. they clearly misguided you at some point or else this wouldn’t have happened.

how did you install OpenCV

[crosspost](https://meta.stackoverflow.com/a/266159):

> <https://stackoverflow.com/questions/78849269/opencv-imshow-error-when-running-even-when-provided-all-parameters>

---

<div class="post-metadata">

**Author:** ![sns123](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/sns123/32/10697_2.png) [@sns123](https://forum.opencv.org/u/sns123)\
**Post date:** [August 9, 2024, 12:15am UTC](https://forum.opencv.org/t/python-opencv-imshow-error-when-running-even-when-provided-all-parameters/18459/3 "2024-08-09T00:15:50Z")

</div>

idk but I check github and this seemed to help:

```auto
pip uninstall opencv-python; pip install opencv-python

```
