Reputation:
Is there a way to force the window displayed by OpenCV (cv2.imshow()
)when displaying an image to fit to the width and height of the image without the need to resize by the mouse it for that ?
Upvotes: 6
Views: 13988
Reputation: 144
In opencv 4.0.0 the below solution works:
import cv2
cv2.namedWindow("myImage", cv2.WINDOW_NORMAL)
image = cv2.imread("./image.jpg")
cv2.imshow("myImage", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Upvotes: 1
Reputation: 7330
You need to pass CV_WINDOW_AUTOSIZE when creating the 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)
Upvotes: 3