-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (41 loc) · 1.73 KB
/
main.py
File metadata and controls
60 lines (41 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import numpy as np
import matplotlib.pyplot as plt
import cv2
import os
from ultralytics import YOLO
def sorted_directory_listing_with_os_listdir(directory):
items = os.listdir(directory)
sorted_items = sorted(items)
return sorted_items
def stritchImages():
stitcher = cv2.Stitcher_create()
files = sorted_directory_listing_with_os_listdir('uploads')
leftImage = cv2.imread('uploads/' + files[0])
count = 0
for file in files[1:]:
rightImage = cv2.imread('uploads/' + file)
status, stitched_image = stitcher.stitch((leftImage, rightImage))
if status == cv2.Stitcher_OK:
print("Stitching successful!")
leftImage = stitched_image
cv2.imwrite("uploads/result.jpg", stitched_image)
count+=1
else:
print("Stitching failed!")
print(count)
def cannyEdgeDetection():
orginalImage = cv2.imread("uploads/result.jpg")
grayImage = cv2.cvtColor(orginalImage, cv2.COLOR_BGR2GRAY)
median_value = np.median(grayImage)
lower_threshold = int(max(0, 0.7 * median_value))
upper_threshold = int(min(255, 1.3 * median_value))
canny_edges = cv2.Canny(grayImage, lower_threshold, upper_threshold)
cv2.imwrite("uploads/cannyResult.jpg", canny_edges)
model = YOLO('yolov8n.pt')
results = model(['static/result.jpg'], classes = 0,conf = 0.5)
for result in results:
boxes = result.boxes # Boxes object for bounding box outputs
masks = result.masks # Masks object for segmentation masks outputs
keypoints = result.keypoints # Keypoints object for pose outputs
probs = result.probs # Probs object for classification outputs
result.save(filename='static/resultHumanDetect.jpg') # save to disk