pythonpython-3.xopencvtrackbar

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


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 ?


Solution

  • 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)