cvview: add c char as calibration

This commit is contained in:
Alon Levy 2023-12-29 17:30:40 +02:00
parent 056bb2f96c
commit 0554eaaafd

View File

@ -1,6 +1,7 @@
import os
import cv2
import argparse
import numpy as np
# Set up the argument parser
parser = argparse.ArgumentParser(description="Visualize image files and display pixel values on hover.")
@ -11,6 +12,27 @@ args = parser.parse_args()
img_path = args.path
def calibrate(x):
x = x.astype(float)
x /= 256.0
#print('{}..{}'.format(x.max(), x.min()))
ret = ((-1.665884e-08) * x**4.
+ (1.347094e-05) * x**3.
+ (-4.396264e-03) * x**2.
+ (9.506939e-01) * x
+ (-6.353247e+01))
#print('{}..{}'.format(ret.max(), ret.min()))
ret = np.where(ret > 0, ret, 0)
#print('{}..{}'.format(ret.max(), ret.min()))
ret = ret.astype('b')
#print('{}..{}'.format(ret.max(), ret.min()))
return ret
class state:
calibrate = False
# Function to display the image and pixel values along with the frame index
def show_pixel_values(image_path):
def mouse_event(event, x, y, flags, param):
@ -28,6 +50,8 @@ def show_pixel_values(image_path):
if img is None:
print(f"Failed to load image at {image_path}. Check the file path and integrity.")
return False
if state.calibrate:
img = calibrate(img)
cv2.namedWindow('Image')
cv2.setMouseCallback('Image', mouse_event)
cv2.imshow('Image', img)
@ -74,6 +98,8 @@ while True:
img_path = modify_filename(img_path, increment=False)
elif key == 93: # ']' key
img_path = modify_filename(img_path, increment=True)
elif key == ord('c'):
state.calibrate = not state.calibrate
# Show the new image
if not show_pixel_values(img_path):