start CV
This commit is contained in:
parent
f8b9ae2443
commit
cde52c4596
BIN
assets/cat_dog.jpg
Normal file
BIN
assets/cat_dog.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
BIN
assets/girl_faces.png
Normal file
BIN
assets/girl_faces.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 334 KiB |
3
projects/CV/.gitignore
vendored
Normal file
3
projects/CV/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
test/
|
||||
capture.png
|
||||
yolov8*.pt
|
1
projects/CV/Assets/cat_dog.jpg
Symbolic link
1
projects/CV/Assets/cat_dog.jpg
Symbolic link
@ -0,0 +1 @@
|
||||
../../../assets/cat_dog.jpg
|
1
projects/CV/Assets/girl_faces.png
Symbolic link
1
projects/CV/Assets/girl_faces.png
Symbolic link
@ -0,0 +1 @@
|
||||
../../../assets/girl_faces.png
|
33
projects/CV/DetectFaces/__main__.py
Normal file
33
projects/CV/DetectFaces/__main__.py
Normal file
@ -0,0 +1,33 @@
|
||||
import cv2
|
||||
|
||||
image_path = './Assets/girl_faces.png'
|
||||
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
|
||||
|
||||
|
||||
def viewImage(image, name_of_window):
|
||||
cv2.namedWindow(name_of_window, cv2.WINDOW_NORMAL)
|
||||
cv2.imshow(name_of_window, image)
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
image = cv2.imread(image_path)
|
||||
|
||||
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
faces = face_cascade.detectMultiScale(
|
||||
gray,
|
||||
scaleFactor=1.1,
|
||||
minNeighbors=5,
|
||||
minSize=(10, 10),
|
||||
)
|
||||
|
||||
faces_detected_string = 'Лиц обнаружено: ' + format(len(faces))
|
||||
print(faces_detected_string)
|
||||
|
||||
# Рисуем квадраты вокруг лиц
|
||||
for x, y, w, h in faces:
|
||||
cv2.rectangle(image, (x, y), (x + w, y + h), (255, 255, 0), 2)
|
||||
|
||||
viewImage(image, faces_detected_string)
|
6
projects/CV/README.md
Normal file
6
projects/CV/README.md
Normal file
@ -0,0 +1,6 @@
|
||||
Python модули
|
||||
-------------
|
||||
|
||||
* `VideoCapture` — модуль для проверки захвата RTSP потока
|
||||
* `DetectFaces` — пример распознования лиц на основе каскада Хаара
|
||||
* `Stream` - пример с сайта `ultralytics` распозования на видео
|
37
projects/CV/Stream/__main__.py
Normal file
37
projects/CV/Stream/__main__.py
Normal file
@ -0,0 +1,37 @@
|
||||
import cv2
|
||||
from ultralytics import YOLO
|
||||
|
||||
# https://docs.ultralytics.com/modes/predict/#streaming-source-for-loop
|
||||
|
||||
# Load the YOLOv8 model
|
||||
model = YOLO('yolov8m.pt')
|
||||
|
||||
# Open the video file
|
||||
video_path = 'run.mp4'
|
||||
cap = cv2.VideoCapture(video_path)
|
||||
|
||||
# Loop through the video frames
|
||||
while cap.isOpened():
|
||||
# Read a frame from the video
|
||||
success, frame = cap.read()
|
||||
|
||||
if success:
|
||||
# Run YOLOv8 inference on the frame
|
||||
results = model(frame)
|
||||
|
||||
# Visualize the results on the frame
|
||||
annotated_frame = results[0].plot()
|
||||
|
||||
# Display the annotated frame
|
||||
cv2.imshow('YOLOv8 Inference', annotated_frame)
|
||||
|
||||
# Break the loop if 'q' is pressed
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
break
|
||||
else:
|
||||
# Break the loop if the end of the video is reached
|
||||
break
|
||||
|
||||
# Release the video capture object and close the display window
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
21
projects/CV/VideoCapture/__main__.py
Normal file
21
projects/CV/VideoCapture/__main__.py
Normal file
@ -0,0 +1,21 @@
|
||||
import cv2
|
||||
|
||||
RTSP_ADDR = "rtsp://localhost:8554/cam"
|
||||
|
||||
cam = cv2.VideoCapture(RTSP_ADDR)
|
||||
|
||||
while True:
|
||||
result, image = cam.read()
|
||||
|
||||
cv2.imshow("Camera", image)
|
||||
|
||||
if cv2.waitKey(1) & 0xFF == ord("s"):
|
||||
cv2.imwrite("capture.png", image)
|
||||
|
||||
if cv2.waitKey(1) & 0xFF == ord("q"):
|
||||
break
|
||||
|
||||
cam.release()
|
||||
|
||||
cv2.destroyWindow("Camera")
|
||||
cv2.destroyAllWindows()
|
28
projects/CV/ex.py
Normal file
28
projects/CV/ex.py
Normal file
@ -0,0 +1,28 @@
|
||||
from ultralytics import YOLO
|
||||
|
||||
model = YOLO('yolov8m.pt')
|
||||
model.save_dir = './predict/'
|
||||
|
||||
result = model.predict(
|
||||
'./Assets/cat_dog.jpg',
|
||||
save=True,
|
||||
device='cpu',
|
||||
show=False,
|
||||
classes=[16, 15],
|
||||
)[0]
|
||||
result = model(
|
||||
'./Assets/cat_dog.jpg',
|
||||
save=True,
|
||||
project='test',
|
||||
name='ololo',
|
||||
device='cpu',
|
||||
show=False,
|
||||
)[0]
|
||||
|
||||
# print(len(result.boxes))
|
||||
|
||||
# for _ in result.boxes:
|
||||
# box = result.boxes[_]
|
||||
# print("Object type:", box.cls)
|
||||
# print("Coordinates:", box.xyxy)
|
||||
# print("Probability:", box.conf)
|
1
projects/CV/haarcascade_frontalface_default.xml
Symbolic link
1
projects/CV/haarcascade_frontalface_default.xml
Symbolic link
@ -0,0 +1 @@
|
||||
/usr/share/opencv4/haarcascades/haarcascade_frontalface_default.xml
|
4
projects/CV/pyproject.toml
Normal file
4
projects/CV/pyproject.toml
Normal file
@ -0,0 +1,4 @@
|
||||
[tool.black]
|
||||
skip-string-normalization = true
|
||||
pycodestyle = true
|
||||
line-length = 100
|
2
projects/CV/requirements.txt
Normal file
2
projects/CV/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
notebook==7.0.4
|
||||
ultralytics==8.0.188
|
Loading…
Reference in New Issue
Block a user