Skip to content

Commit

Permalink
Initial opencv testing
Browse files Browse the repository at this point in the history
  • Loading branch information
furrysalamander committed Feb 2, 2023
1 parent 2ea697d commit 309e780
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM debian:bullseye-slim

# RUN apk add --no-cache make automake gcc g++ subversion python3-dev
# RUN apk add --no-cache python3 py3-pip
RUN apt-get update && apt-get install -y python3 python3-pip
RUN pip3 install opencv-python-headless
# RUN pip3 install --upgrade pip setuptools wheel
# RUN pip3 install opencv-python
# RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 -y
7 changes: 7 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "rubedo",
"build": {
"dockerfile":"Dockerfile"
},
"extensions": ["ms-python.python", "076923.python-image-preview"]
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

frame_data/
.idea/
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
// "python.jediEnabled": false,
"python.autoComplete.extraPaths": [
"/usr/local/lib/python3.9/dist-packages/cv2/python-3.9"
],
"python.analysis.extraPaths": [
"/usr/local/lib/python3.9/dist-packages/cv2/python-3.9"
]
}
62 changes: 62 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import cv2
import numpy as np

# result = cv2.imread("2023-01-16-213226.jpg")

video_data = cv2.VideoCapture("sample_video.mp4")

out = cv2.VideoWriter("out.avi", cv2.VideoWriter_fourcc('M','J','P','G'), 14.97, (400,400))

mid_y = 2592//2
mid_x = 1944//2

frame_index = 0

while video_data.isOpened():
ret, frame = video_data.read()
if not ret:
break
frame = frame[mid_y-200:mid_y+200, mid_x+400:mid_x+800]

lowerb = np.array([0, 0, 150])
upperb = np.array([255, 255, 255])
red_line = cv2.inRange(frame, lowerb, upperb)

masked_video = cv2.bitwise_and(frame,frame,mask = red_line)
# out.write(masked_video)

gray = cv2.cvtColor(masked_video, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (11, 11), 0)

frame_brightest_x = []

for line in gray:
# find the 4 brightest pixels
if line.max() > 0:
brightest_pixels = np.argsort(line)[-4:]
line_brightest_x = np.average(brightest_pixels)
frame_brightest_x.append(line_brightest_x)

gray = cv2.cvtColor(gray, cv2.COLOR_GRAY2BGR)

if len(frame_brightest_x) > 0:
out.write(gray)
cv2.imwrite(f"frame_data/{frame_index}.png", gray)

print(frame_index, np.std(frame_brightest_x))
frame_index += 1
# red_line = cv2.cvtColor(red_line, cv2.COLOR_GRAY2BGR)
# out.write(red_line)


out.release()
# cv2.imwrite("test.png", frame)

# line starts on frame 12
# line ends on frame 32
# line starts on frame 41
# line ends on 61
# line starts on 70
# line ends on 90
# line starts on 99
# line ends on 119

0 comments on commit 309e780

Please sign in to comment.