Made Readme

This commit is contained in:
2021-11-11 07:20:25 -06:00
parent 0331882a49
commit 7770180ea5
3 changed files with 44 additions and 8 deletions

View File

@@ -1,3 +0,0 @@
{
"python.pythonPath": "/bin/python"
}

20
README.md Normal file
View File

@@ -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.

29
main.py
View File

@@ -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