You need to pass CV_WINDOW_AUTOSIZE when creating namedWindow (or WINDOW_AUTOSIZE if you import cv2 instead of cv )
Here is an example:
cv2.namedWindow("window", cv2.WINDOW_AUTOSIZE) # or cv.namedWindow("window",cv.CV_WINDOW_AUTOSIZE) cv2.imshow("window", yourimage)
source share