Created
November 16, 2020 14:05
-
-
Save thibthibaut/a2fa22b2c9b9df4e5d0237dcdbbf2832 to your computer and use it in GitHub Desktop.
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
''' | |
Sharpness detector | |
Copyright (c) 1991 - 2024 THIBAUTV CORPORATION | |
Warning This software is under beerware licence. By using it you agree to the | |
terms and conditions of this licence. See below. | |
---------------------------------------------------------------------------- | |
"THE BEER-WARE LICENSE" (Revision 42): | |
Thibaut V wrote this file. As long as you retain this notice you | |
can do whatever you want with this stuff. If we meet some day, and you think | |
this stuff is worth it, you can buy me a beer in return. | |
Thibaut V | |
---------------------------------------------------------------------------- | |
''' | |
import cv2 | |
cam = cv2.VideoCapture(1) | |
cv2.namedWindow('calibration') | |
while True: | |
ret, frame = cam.read() | |
if not ret: | |
print("failed to grab frame") | |
break | |
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |
sharpness = cv2.Laplacian(gray, cv2.CV_16S).var() | |
cv2.putText(frame, f'Sharpness: {int(sharpness)}', (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 1, cv2.LINE_AA) | |
cv2.imshow('calibration', frame) | |
k = cv2.waitKey(1) | |
if k%256 == 27: | |
# ESC pressed | |
break | |
cam.release() | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment