From 7770180ea53a1c17a4d4839ccee2489267ae0d21 Mon Sep 17 00:00:00 2001 From: RobViren Date: Thu, 11 Nov 2021 07:20:25 -0600 Subject: [PATCH] Made Readme --- .vscode/settings.json | 3 --- README.md | 20 ++++++++++++++++++++ main.py | 29 ++++++++++++++++++++++++----- 3 files changed, 44 insertions(+), 8 deletions(-) delete mode 100644 .vscode/settings.json create mode 100644 README.md diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index b26f7c4..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "python.pythonPath": "/bin/python" -} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8b6999a --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# Kestrel focusing script + +## Requirements +make sure to install python 3.9.7 or better +Install requirements with +```pthon +python3 -m pip install -r requirements.txt +``` +It could also be just python depending on system naming conventions +```pthon +python -m pip install -r requirements.txt +``` + +## Description +The script will pull from the video device described by +```python +cap = cv2.VideoCapture(1) +``` +where the number is the video device iterated by the operating system. If you have only one device it will be populated on "0". If you have two, than the second would be populated on "1". Change this according to your setup. + diff --git a/main.py b/main.py index 5b994eb..cafc64f 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,13 @@ import cv2 import numpy as np + +# Capture device number cap = cv2.VideoCapture(1) + +# Set capture resolution cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280) cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720) -max_count = 0 +max_count = 1 # Text font = cv2.FONT_HERSHEY_SIMPLEX @@ -12,31 +16,46 @@ org2 = (50, 90) fontScale = 1 color = (255, 0, 0) thickness = 2 + +# Subwindow size scale = 6 + +# Main loop while True: + #Grab frame ret, src = cap.read() + + # Get sub window size center = (int(src.shape[0]/2),int(src.shape[1]/2)) upper_left = (int(center[1] - src.shape[1]/scale),int(center[0] - src.shape[0]/scale)) lower_right = (int(center[1] + src.shape[1]/scale),int(center[0] + src.shape[0]/scale)) + # Color conversion gray = cv2.cvtColor(src[upper_left[1]:lower_right[1],upper_left[0]:lower_right[0]], cv2.COLOR_BGR2GRAY) + # Edge detection sobel = cv2.Sobel(gray, cv2.CV_8U, 1, 0, ksize=3) + # Thresholding operation t, thresh = cv2.threshold(sobel, 200, 255, cv2.THRESH_BINARY) count = np.sum(sobel) if count > max_count: max_count = count + # Text rendering src = cv2.putText(src, 'Max: {}'.format(int(max_count/10000)), org, font, fontScale, color, thickness, cv2.LINE_AA) src = cv2.putText(src, 'Current: {:.2f}%'.format((count/max_count)*100 - 0.01), org2, font, fontScale, color, thickness, cv2.LINE_AA) + # Subwindow Outline src = cv2.rectangle(src, pt1=upper_left, pt2=lower_right, color=(36,255,12), thickness=1) + + #Display of results cv2.imshow('tresh', thresh) cv2.imshow('src', src) cv2.imshow('sobel', sobel) - + + # Frame waiting and logic loop k = cv2.waitKey(10) - if k == 27: + if k == 27: #Escape key to escape break - elif k == 32: - max_count = 0 + elif k == 32: # Spacebar to reset count + max_count = 1