Created
April 23, 2021 10:40
-
-
Save schuhumi/0e39ac09d00683f5aa76d4e3e927654d to your computer and use it in GitHub Desktop.
simply plot float matrices with OpenCV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
class cvWindows: | |
def __init__(self): | |
self.windowlist = [] | |
def imshow(self, name, mat): | |
cv2.namedWindow(name, cv2.WINDOW_NORMAL | cv2.WINDOW_GUI_EXPANDED) | |
cv2.imshow(name, mat) | |
self.windowlist.append(name) | |
def imshowAutoScale(self, name, mat): | |
print(f"cvWindows.imshowAutoScale: {np.min(mat)=} {np.max(mat)=}") | |
tmp = mat-np.min(mat) | |
tmp /= np.max(tmp) | |
self.imshow(name, tmp) | |
def waitAndDestroy(self): | |
while True: | |
if cv2.waitKey(100)==27: | |
break | |
if any( cv2.getWindowProperty(name,cv2.WND_PROP_VISIBLE)<1 for name in self.windowlist): | |
break | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment