forked from APAP-ICT/APAP-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 이상상황 영상 저장 삭제 - 위험지역 침입 operation 추가
- Loading branch information
Showing
4 changed files
with
102 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from enum import StrEnum | ||
|
||
from model.detect import estimate_distance, area_intrusion | ||
from model.schema import DetectionResult | ||
|
||
|
||
class OperationType(StrEnum): | ||
ESTIMATE_DISTANCE = "estimate_distance", | ||
AREA_INTRUSION = "area_intrusion" | ||
|
||
|
||
def define_operation(op: OperationType): | ||
if op == OperationType.ESTIMATE_DISTANCE: | ||
return handle_estimate_distance | ||
elif op == OperationType.AREA_INTRUSION: | ||
return handle_area_intrusion | ||
|
||
|
||
def handle_estimate_distance(img) -> tuple[bool, DetectionResult]: | ||
distances, result = estimate_distance(img) | ||
pattern_detected = any(distance <= 200 for _, _, distance in distances) | ||
|
||
return pattern_detected, result | ||
|
||
|
||
def handle_area_intrusion(img) -> tuple[bool, DetectionResult]: | ||
intrusion, result = area_intrusion(img) | ||
return intrusion, result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import cv2 | ||
|
||
from model.operations import handle_area_intrusion | ||
|
||
|
||
def test_area_intrusion(): | ||
cap = cv2.VideoCapture("resources/person.mp4") | ||
assert cap.isOpened(), "Error reading video file" | ||
|
||
while cap.isOpened(): | ||
success, im0 = cap.read() | ||
if not success: | ||
print("Video frame is empty or video processing has been successfully completed.") | ||
break | ||
|
||
pattern_detected, result = handle_area_intrusion(im0) | ||
|
||
cv2.imshow("Object Tracking", result.plot_image) | ||
if cv2.waitKey(1) & 0xFF == ord('q'): | ||
break | ||
|
||
cap.release() | ||
cv2.destroyAllWindows() |