OpenCV error while reszing new created window is there any other way to do it?

Viewed 74
cv2.namedWindow("Trackbars")
cv2.resize("Trackbars", 640 ,420)
cv2.createTrackbar("Hue Min","Trackbars",0,179,empty)

I am using this code to create and resize the new window but its showing giving me following error: what am doing wrong here ?

Overload resolution failed:

  • src is not a numpy array, neither a scalar
  • Expected Ptr<cv::UMat> for argument 'src'

what is wrong here ?

2 Answers

There are two slightly different ways to do this.

I would recommend changing resize to resizeWindow. cv2.WINDOW_KEEPRATIO keeps the correct ratio of an image (if you have one).

cv2.namedWindow("Trackbars", cv2.WINDOW_KEEPRATIO)
cv2.resizeWindow("Trackbar", 640, 420)

You could also resize the window in a ratio form instead of a specific pixel - this is if you have the media input as a variable (image).

cv2.resize(frame, (0,0), fx=0.4, fy=0.4)

cv2.resize("Trackbars", 640 ,420)
"Trackbars" is not an numpy array. Add an image here. hence src error. Use cv2.imread to read your image or from another source.
Secondly, 640, 420 should be a tuple (640,420) i.e dimensions.

Related