Made Readme
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"python.pythonPath": "/bin/python"
|
|
||||||
}
|
|
||||||
20
README.md
Normal file
20
README.md
Normal 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
29
main.py
@@ -1,9 +1,13 @@
|
|||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
# Capture device number
|
||||||
cap = cv2.VideoCapture(1)
|
cap = cv2.VideoCapture(1)
|
||||||
|
|
||||||
|
# Set capture resolution
|
||||||
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
|
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
|
||||||
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
|
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
|
||||||
max_count = 0
|
max_count = 1
|
||||||
|
|
||||||
# Text
|
# Text
|
||||||
font = cv2.FONT_HERSHEY_SIMPLEX
|
font = cv2.FONT_HERSHEY_SIMPLEX
|
||||||
@@ -12,31 +16,46 @@ org2 = (50, 90)
|
|||||||
fontScale = 1
|
fontScale = 1
|
||||||
color = (255, 0, 0)
|
color = (255, 0, 0)
|
||||||
thickness = 2
|
thickness = 2
|
||||||
|
|
||||||
|
# Subwindow size
|
||||||
scale = 6
|
scale = 6
|
||||||
|
|
||||||
|
# Main loop
|
||||||
while True:
|
while True:
|
||||||
|
#Grab frame
|
||||||
ret, src = cap.read()
|
ret, src = cap.read()
|
||||||
|
|
||||||
|
# Get sub window size
|
||||||
center = (int(src.shape[0]/2),int(src.shape[1]/2))
|
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))
|
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))
|
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)
|
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)
|
sobel = cv2.Sobel(gray, cv2.CV_8U, 1, 0, ksize=3)
|
||||||
|
# Thresholding operation
|
||||||
t, thresh = cv2.threshold(sobel, 200, 255, cv2.THRESH_BINARY)
|
t, thresh = cv2.threshold(sobel, 200, 255, cv2.THRESH_BINARY)
|
||||||
count = np.sum(sobel)
|
count = np.sum(sobel)
|
||||||
if count > max_count:
|
if count > max_count:
|
||||||
max_count = count
|
max_count = count
|
||||||
|
|
||||||
|
# Text rendering
|
||||||
src = cv2.putText(src, 'Max: {}'.format(int(max_count/10000)), org, font, fontScale,
|
src = cv2.putText(src, 'Max: {}'.format(int(max_count/10000)), org, font, fontScale,
|
||||||
color, thickness, cv2.LINE_AA)
|
color, thickness, cv2.LINE_AA)
|
||||||
src = cv2.putText(src, 'Current: {:.2f}%'.format((count/max_count)*100 - 0.01), org2, font, fontScale,
|
src = cv2.putText(src, 'Current: {:.2f}%'.format((count/max_count)*100 - 0.01), org2, font, fontScale,
|
||||||
color, thickness, cv2.LINE_AA)
|
color, thickness, cv2.LINE_AA)
|
||||||
|
# Subwindow Outline
|
||||||
src = cv2.rectangle(src, pt1=upper_left, pt2=lower_right, color=(36,255,12), thickness=1)
|
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('tresh', thresh)
|
||||||
cv2.imshow('src', src)
|
cv2.imshow('src', src)
|
||||||
cv2.imshow('sobel', sobel)
|
cv2.imshow('sobel', sobel)
|
||||||
|
|
||||||
|
# Frame waiting and logic loop
|
||||||
k = cv2.waitKey(10)
|
k = cv2.waitKey(10)
|
||||||
if k == 27:
|
if k == 27: #Escape key to escape
|
||||||
break
|
break
|
||||||
elif k == 32:
|
elif k == 32: # Spacebar to reset count
|
||||||
max_count = 0
|
max_count = 1
|
||||||
|
|||||||
Reference in New Issue
Block a user