[code][code python][code python][code html][code python][code python][code python][code python][code python][code python][code python][code python][code html][code javascript][code python][code python][code python][code python][code python][code python][/code][/code][/code][/code][/code][/code][/code][/code][/code][/code][/code][/code][/code][/code][/code][/code][/code][/code][/code][/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)
rowsAvaible = isinstance(imgArray, list)
w = imgArray.shape
h = imgArray.shape
if rowsAvaible:
for x in range(0, rows):
for y in range(0, cols):
if imgArray.shape == imgArray.shape:
imgArray = cv2.resize(imgArray, (0, 0), None, scale, scale)
else:
imgArray = cv2.resize(imgArray, (imgArray.shape,imgArray.shape), None, scale, scale)
if len(imgArray.shape) == 2:imgArray = cv2.cvtColor(imgArray, cv2.COLOR_GRAY2BGR)
imageBlank = np.zeros((h, w, 3), np.uint8)
hor = *rows
hor_con = *rows
for x in range(0, rows):
hor = np.hstack(imgArray)
ver = np.vstack(hor)
else:
for x in range(0, rows):
if imgArray.shape == imgArray.shape:
imgArray = cv2.resize(imgArray, (0, 0), None, scale, scale)
else:
imgArray = cv2.resize(imgArray, (imgArray.shape, imgArray.shape), None, scale, scale)
if len (imgArray.shape) == 2:imgArray = cv2.cvtColor(imgArray, 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,())
cv2.imshow(“Result”, imgStack)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
and it throws an error:
File “C:\Users\Даниил\PycharmProjects\ob ject_detection\real_time_object_det ection.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\w indow.cpp:862: error: (-215:Assertion failed) trackbar in function ‘cv::getTrackbarPos
I don’t know what to do with it, please help, thanks in advance.