hunglc007 / tensorflow-yolov4-tflite

YOLOv4, YOLOv4-tiny, YOLOv3, YOLOv3-tiny Implemented in Tensorflow 2.0, Android. Convert YOLO v4 .weights tensorflow, tensorrt and tflite
https://github.com/hunglc007/tensorflow-yolov4-tflite
MIT License
2.23k stars 1.24k forks source link

cv2.error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'resize' #446

Open DaniilKochkurov opened 2 years ago

DaniilKochkurov commented 2 years ago

Hello! I am writing a program to recognize the contours of objects. Here is my code

import cv2 import numpy as np

frameW = 640 frameH = 480 cap = cv2.VideoCapture(0) cap.set(3, frameW) cap.set(4, frameH)

def empty(a): pass

cv2.namedWindow("Parametrs") cv2.resizeWindow("Parametrs", 640, 480) cv2.createTrackbar("Threshold1", "Parametrs", 150, 255, empty) cv2.createTrackbar("Threshold2", "Parametrs", 255, 255, empty)

def stackImages(scale, imgArray): rows = len(imgArray) cols = len(imgArray[0]) rowsAvaible = isinstance(imgArray[0], list) w = imgArray[0][0].shape[1] h = imgArray[0][0].shape[0] if rowsAvaible: for x in range(0, rows): for y in range(0, cols): if imgArray[x][y].shape[:2] == imgArray[0][0].shape[:2]: imgArray[x][y] = cv2.resize(imgArray[x][y], (0, 0), None, scale, scale) else: imgArray[x][y] = cv2.resize(imgArray[x][y], (imgArray[0][0].shape[1],imgArray[0][0].shape[0]), None, scale, scale) if len(imgArray[x][y].shape) == 2:imgArray[x][y] = cv2.cvtColor(imgArray[x][y], cv2.COLOR_GRAY2BGR) imageBlank = np.zeros((h, w, 3), np.uint8) hor = [imageBlank]rows hor_con = [imageBlank]rows for x in range(0, rows): hor[x] = np.hstack(imgArray[x]) ver = np.vstack(hor) else: for x in range(0, rows): if imgArray[x].shape[:2] == imgArray[0].shape[:2]: imgArray[x] = cv2.resize(imgArray[x], (0, 0), None, scale, scale) else: imgArray[x] = cv2.resize(imgArray[x], (imgArray[0].shape[1], imgArray[0].shape[0]), None, scale, scale) if len (imgArray[x].shape) == 2:imgArray[x] = cv2.cvtColor(imgArray[x], cv2.COLOR_GRAY2BGR) hor = np.hstack(imgArray) ver = hor return ver

while True: success, img = cap.read()

imgBlur = cv2.GaussianBlur(img, (7, 7), 1 )
imgGray = cv2.cvtColor(imgBlur, cv2.COLOR_BGR2GRAY)

theshold1 = cv2.getTrackbarPos("Theshold1", "Parametrs")
theshold2 = cv2.getTrackbarPos("Theshold2", "Parametrs")
imgCanny = cv2.Canny(imgGray, theshold1, theshold2)

imgStack = stackImages(0.8,([img, imgGray, imgCanny]))
cv2.imshow("Result", imgStack)
if cv2.waitKey(1) & 0xFF == ord('q'):
    break

and it throws an error: File "C:\Users\Даниил\PycharmProjects\object_detection\real_time_object_detection.py", line 58, in theshold1 = cv2.getTrackbarPos("Theshold1", "Parametrs") cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp real_time_object_detecnion.txt :862: error: (-215:Assertion failed) trackbar in function 'cv::getTrackbarPos I don't know what to do with it, please help, thanks in advance.