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
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.
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()
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.