Added bounding box aroung the hedgehog for the IR video
This commit is contained in:
parent
a3178b15bd
commit
3f114dd792
3 changed files with 69 additions and 1 deletions
1
Pipfile
1
Pipfile
|
|
@ -7,6 +7,7 @@ name = "pypi"
|
||||||
pyserial = "*"
|
pyserial = "*"
|
||||||
matplotlib = "*"
|
matplotlib = "*"
|
||||||
opencv-python = "*"
|
opencv-python = "*"
|
||||||
|
imutils = "*"
|
||||||
|
|
||||||
[dev-packages]
|
[dev-packages]
|
||||||
|
|
||||||
|
|
|
||||||
9
Pipfile.lock
generated
9
Pipfile.lock
generated
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"_meta": {
|
"_meta": {
|
||||||
"hash": {
|
"hash": {
|
||||||
"sha256": "cfeb134953c2360663a51e5238f6c573c2a9ff637cee621f45aedadd9b5b432d"
|
"sha256": "b4cc5fe5d9d7af541c033d4f692a774ea0d60013b0d2594b1cdbb648b09c8cce"
|
||||||
},
|
},
|
||||||
"pipfile-spec": 6,
|
"pipfile-spec": 6,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
|
@ -136,6 +136,13 @@
|
||||||
"markers": "python_version >= '3.9'",
|
"markers": "python_version >= '3.9'",
|
||||||
"version": "==4.58.1"
|
"version": "==4.58.1"
|
||||||
},
|
},
|
||||||
|
"imutils": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:03827a9fca8b5c540305c0844a62591cf35a0caec199cb0f2f0a4a0fb15d8f24"
|
||||||
|
],
|
||||||
|
"index": "pypi",
|
||||||
|
"version": "==0.5.4"
|
||||||
|
},
|
||||||
"kiwisolver": {
|
"kiwisolver": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:01c3d31902c7db5fb6182832713d3b4122ad9317c2c5877d0539227d96bb2e50",
|
"sha256:01c3d31902c7db5fb6182832713d3b4122ad9317c2c5877d0539227d96bb2e50",
|
||||||
|
|
|
||||||
60
hedgehogbox.py
Normal file
60
hedgehogbox.py
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import cv2
|
||||||
|
import imutils
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = ArgumentParser()
|
||||||
|
parser.add_argument("--output", type=Path, required=False, default="output.avi")
|
||||||
|
parser.add_argument("video_file", type=Path)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
cap = cv2.VideoCapture(args.video_file)
|
||||||
|
output = cv2.VideoWriter(args.output, cv2.VideoWriter_fourcc(*'MPEG'), 30, (720, 1792))
|
||||||
|
|
||||||
|
static_frame = None
|
||||||
|
|
||||||
|
while True:
|
||||||
|
ret, frame = cap.read()
|
||||||
|
if ret:
|
||||||
|
cropped_frame = frame[55:720, 0:540]
|
||||||
|
grey_frame = cv2.cvtColor(cropped_frame, cv2.COLOR_BGR2GRAY)
|
||||||
|
|
||||||
|
if static_frame is None:
|
||||||
|
static_frame = grey_frame
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
_, thresh = cv2.threshold(grey_frame, 120, 255, cv2.THRESH_BINARY)
|
||||||
|
dilated_image = cv2.dilate(thresh, None, iterations=2)
|
||||||
|
|
||||||
|
cnts = cv2.findContours(dilated_image.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
||||||
|
cnts = imutils.grab_contours(cnts)
|
||||||
|
|
||||||
|
for c in cnts:
|
||||||
|
if cv2.contourArea(c) < 700:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# get the bounding box coordinates
|
||||||
|
(x, y, w, h) = cv2.boundingRect(c)
|
||||||
|
cv2.rectangle(cropped_frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
|
||||||
|
|
||||||
|
output.write(frame)
|
||||||
|
cv2.imshow("output", frame)
|
||||||
|
|
||||||
|
# exit if 's' key is pressed
|
||||||
|
if cv2.waitKey(1) & 0xFF == ord('s'):
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("Could not read frame!")
|
||||||
|
break
|
||||||
|
|
||||||
|
cv2.destroyAllWindows()
|
||||||
|
output.release()
|
||||||
|
cap.release()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Add table
Reference in a new issue