2 Commits

Author SHA1 Message Date
6ab584a715 yolov5 install 추가 2024-03-04 14:42:22 +09:00
33ffaef63d use ai 2024-03-04 14:34:25 +09:00
24 changed files with 729 additions and 861 deletions

0
AI_ENGINE/DATA/CON.mp4 Normal file → Executable file
View File

BIN
AI_ENGINE/DATA/Trim.mp4 Normal file

Binary file not shown.

BIN
AI_ENGINE/DATA/WD.mp4 Normal file

Binary file not shown.

BIN
AI_ENGINE/DATA/WD_crop.mp4 Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 70 KiB

View File

@@ -42,7 +42,7 @@ def _bi_sftp_upload():
remotepath = AI_CONST.FTP_LOCATION + os.sep + AI_CONST.FTP_BI_FILE_NAME + '.jpg'
#sftp.put(AI_CONST.FTP_BI_RESULT, remotepath)
sftp.put(AI_CONST.FTP_BI_RESULT, remotepath)
sftp.close()
transprot.close()

View File

@@ -42,3 +42,6 @@ client.on_disconnect = on_disconnect
client.username_pw_set(AI_CONST.MQTT_USER_ID,AI_CONST.MQTT_USER_PW)
# address : localhost, port: 1883 에 연결
client.connect(AI_CONST.MQTT_HOST, AI_CONST.MQTT_PORT)

View File

@@ -56,9 +56,4 @@ client.username_pw_set(AI_CONST.MQTT_USER_ID, AI_CONST.MQTT_USER_PW)
client.connect(AI_CONST.MQTT_HOST, AI_CONST.MQTT_PORT)
client.subscribe(AI_CONST.MQTT_PPE_TOPIC) # ppe
client.subscribe(AI_CONST.MQTT_FR_TOPIC) # FR
client.loop_forever()

View File

@@ -120,7 +120,7 @@ class FaceDetect:
remotepath = self.ftp_info.location + os.sep + self.ftp_info.file_face + '.jpg'
#sftp.put(AI_CONST.FTP_FR_RESULT, remotepath)
sftp.put(AI_CONST.FTP_FR_RESULT, remotepath)
sftp.close()
transprot.close()
@@ -155,6 +155,7 @@ class FaceDetect:
def _result_update(self, matched_list: list):
"""
:param matched_list: detect 된 object list
"""
self.mqtt_status = self.thread_value.STATUS_NONE # status init
@@ -330,8 +331,14 @@ class FaceDetect:
'encoding' : face_recognition.face_encodings(worker22_image)[0]
}
worker100_image = face_recognition.load_image_file(AI_CONST.WORKER100_IMG_PATH)
no000100 = {
'target_names' : 'no000100',
'encoding' : face_recognition.face_encodings(worker100_image)[0]
}
encoding_list = [
#no000001,no000002,no000003 # kepco 1
# no000001,no000002,no000003, # test 1
# ,
no000004 # jangys
,no000005 # whangsj
@@ -343,7 +350,7 @@ class FaceDetect:
# ,no000010,no000011,no000012,no000015,no000018 #Helmet on kepco2
,no000019,no000020 #Helmet off kepco 2
,no000021 #,no000022
,no000100 # test
]
result = []
@@ -352,7 +359,7 @@ class FaceDetect:
result.append(i["encoding"])
names = [
#'no000001','no000002','no000003'# kepco 1
# 'no000001','no000002','no000003',# test 1
# ,
'no000004' # jangys
,'no000005' # whangsj
@@ -364,6 +371,7 @@ class FaceDetect:
# ,'no000010','no000011','no000012','no000015','no000018' #Helmet on kepco2
,'no000019','no000020' #Helmet off kepco 2
,'no000021' #,no000022
# ,'no000100' #test
]
return result , names
@@ -411,70 +419,62 @@ class FaceDetect:
# face_encodings = []
# while self.mqtt_status != self.thread_value.STATUS_COMPLETE and self.stop_sign != True:
# while True:
while True:
# # TODO(JWKIM):ageing test 23-02-28
# # self._mqtt_publish(status="AGEING_TEST")
# TODO(JWKIM):ageing test 23-02-28
# self._mqtt_publish(status="AGEING_TEST")
# # loop stop
# if self.stop_event.is_set():
# if self.mqtt_status == self.thread_value.STATUS_COMPLETE:
# pass
# else:
# self.thread_value.current_status = self.thread_value.STATUS_STOP
# # TODO(JWKIM):ageing test 23-02-28
# break
# elif self.thread_value.timeout_status:
# self.thread_value.current_status = self.thread_value.STATUS_TIMEOUT
# # TODO(JWKIM):ageing test 23-02-28
# break
# loop stop
if self.stop_event.is_set():
if self.mqtt_status == self.thread_value.STATUS_COMPLETE:
pass
else:
self.thread_value.current_status = self.thread_value.STATUS_STOP
# TODO(JWKIM):ageing test 23-02-28
break
elif self.thread_value.timeout_status:
self.thread_value.current_status = self.thread_value.STATUS_TIMEOUT
# TODO(JWKIM):ageing test 23-02-28
break
# Grab a single frame of video
ret, frame = input_movie.read()
cv2.imwrite(AI_CONST.FTP_FR_RESULT,frame)
self._sftp_upload()
self.result = ["no000010"]
ret, frame = input_movie.read()
self._mqtt_publish(status = self.thread_value.STATUS_COMPLETE)
# Quit when the input video file ends
# 영상파일일 경우 다시 재생
# if not ret and os.path.isfile(self.input_video):
# input_movie = cv2.VideoCapture(self.input_video)
# continue
if not ret and os.path.isfile(self.input_video):
input_movie = cv2.VideoCapture(self.input_video)
continue
# frame_count = int(input_movie.get(cv2.CV_CAP_PROP_FPS))
# Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
# rgb_frame = frame[:, :, ::-1]
rgb_frame = frame[:, :, ::-1]
# face_locations = face_recognition.face_locations(rgb_frame)
# face_encodings = face_recognition.face_encodings(rgb_frame, face_locations)
# for face_encoding in face_encodings:
face_locations = face_recognition.face_locations(rgb_frame)
face_encodings = face_recognition.face_encodings(rgb_frame, face_locations)
for face_encoding in face_encodings:
# matched_name = [] # detect 완료된 명단
matched_name = [] # detect 완료된 명단
# match = face_recognition.compare_faces(known_faces, face_encoding, tolerance=AI_CONST.FACE_EVOLUTION_DISTANCE)
match = face_recognition.compare_faces(known_faces, face_encoding, tolerance=AI_CONST.FACE_EVOLUTION_DISTANCE)
# #TODO(jwkim): 입력 이미지 변경
# if self.fr_manager.fr_id_info != self.id_info:
# raise Exception(AI_CONST.IMG_CHANGED_MSG)
#TODO(jwkim): 입력 이미지 변경
if self.fr_manager.fr_id_info != self.id_info:
raise Exception(AI_CONST.IMG_CHANGED_MSG)
# face_distances = face_recognition.face_distance(known_faces, face_encoding)
# best_match_index = np.argmin(face_distances)
face_distances = face_recognition.face_distance(known_faces, face_encoding)
best_match_index = np.argmin(face_distances)
# if face_distances[best_match_index] < AI_CONST.FACE_EVOLUTION_DISTANCE :
# #demo
# print(match)
# if match[best_match_index]:
if face_distances[best_match_index] < AI_CONST.FACE_EVOLUTION_DISTANCE :
#demo
if match[best_match_index]:
# # self.result[0] = known_names[best_match_index]
# self.result[0] = "no000010"
# self.mqtt_status = self.thread_value.STATUS_COMPLETE
# print(known_names[best_match_index])
# self.stop_event.set()
# break
self.result[0] = "no000010"
print(known_names[best_match_index])
self.mqtt_status = self.thread_value.STATUS_COMPLETE
self.stop_event.set()
break
# if match[best_match_index]:
# matched_name.append(self.worker_names[best_match_index])
@@ -486,52 +486,47 @@ class FaceDetect:
# ri
# self._ai_rbi(matched_name)
# if self.mqtt_status == self.thread_value.STATUS_NEW:
# self._mqtt_publish(self.thread_value.STATUS_NEW)
if self.mqtt_status == self.thread_value.STATUS_NEW:
self._mqtt_publish(self.thread_value.STATUS_NEW)
# # input source check
# self._source_check()
# input source check
self._source_check()
# # loop stop
# if self.stop_event.is_set():
# if self.mqtt_status == self.thread_value.STATUS_COMPLETE:
# self.result_frame = copy.deepcopy(frame)
# else:
# self.thread_value.current_status = self.thread_value.STATUS_STOP
# # TODO(JWKIM):ageing test 23-02-28
# break
# elif self.thread_value.timeout_status:
# self.thread_value.current_status = self.thread_value.STATUS_TIMEOUT
# # TODO(JWKIM):ageing test 23-02-28
# break
# loop stop
if self.stop_event.is_set():
# if self.thread_value.timeout_status:
# self._mqtt_publish(self.thread_value.STATUS_TIMEOUT)
# self.thread_value.timeout_status = False
if self.mqtt_status == self.thread_value.STATUS_COMPLETE:
self.result_frame = copy.deepcopy(frame)
else:
self.thread_value.current_status = self.thread_value.STATUS_STOP
# TODO(JWKIM):ageing test 23-02-28
break
elif self.thread_value.timeout_status:
self.thread_value.current_status = self.thread_value.STATUS_TIMEOUT
# TODO(JWKIM):ageing test 23-02-28
break
# elif self.stop_event.is_set():
# if self.mqtt_status == self.thread_value.STATUS_COMPLETE:
# #sftp
# cv2.imwrite(AI_CONST.FTP_FR_RESULT,self.result_frame)
# if project_config.SFTP_UPLOAD and project_config.FR_UPLOAD:
# self.snapshot_path = self._sftp_upload()
# else:
# self.snapshot_path = None
# self._mqtt_publish(self.thread_value.STATUS_COMPLETE)
# else:
# self._mqtt_publish(self.thread_value.STATUS_STOP)
if self.thread_value.timeout_status:
self._mqtt_publish(self.thread_value.STATUS_TIMEOUT)
self.thread_value.timeout_status = False
# if not self.timeout_event.is_set():
# self.timeout_event.set()
elif self.stop_event.is_set():
if self.mqtt_status == self.thread_value.STATUS_COMPLETE:
#sftp
cv2.imwrite(AI_CONST.FTP_FR_RESULT,self.result_frame)
self.snapshot_path = self._sftp_upload()
self._mqtt_publish(self.thread_value.STATUS_COMPLETE)
else:
self._mqtt_publish(self.thread_value.STATUS_STOP)
# self.timeout_event.clear()
if not self.timeout_event.is_set():
self.timeout_event.set()
self.timeout_event.clear()
# if self.mqtt_status == self.thread_value.STATUS_COMPLETE:
if self.mqtt_status == self.thread_value.STATUS_COMPLETE:
# pass
pass
except Exception as e:
print(e)

File diff suppressed because it is too large Load Diff

View File

@@ -1 +1 @@
rtsp://admin:admin1263!@10.20.10.99:28554/onvif/media?profile=Profile2
rtsp://admin:admin1263!@10.20.10.99:554/onvif/media?profile=Profile2

View File

@@ -34,7 +34,7 @@
export BUILD_VERSION=0.13.0
python3 setup.py install --user
```
### yolov5 install
DL/OD 폴더에 저장
```

View File

@@ -18,7 +18,6 @@ from sqlalchemy.orm import Session
from starlette.requests import Request
import copy
import time
import threading
AI_ENGINE_PATH = "/AI_ENGINE"
@@ -289,7 +288,6 @@ async def ai_engine_od_con_setup_detect(request: Request, request_body_info: M.A
}
```
"""
# time.sleep(2)
global engine_info
message_queue.sender({
@@ -592,7 +590,6 @@ async def ai_engine_od_ppe_detect(request: Request, request_body_info: M.AEAIMod
}
```
"""
# time.sleep(2)
global engine_info
message_queue.sender({
@@ -768,7 +765,6 @@ async def ai_engine_od_work_detect(request: Request, request_body_info: M.AEAIMo
}
```
"""
global engine_info
message_queue.sender({
@@ -854,7 +850,7 @@ async def ai_engine_bi_detect(request: Request, request_body_info: M.AEAIModelRB
# DEMO.demo_wd_bi(2)
# DEMO.bi_snap_shot()
DEMO.bi_snap_shot()
result = M.ResponseBase()

View File

@@ -52,24 +52,24 @@ elif project_config.CONFIG == project_config.CONFIG_MG:
# MQTT_USER_ID = 'admin'
# MQTT_USER_PW = 'admin'
MQTT_PORT = 11883
MQTT_PORT = 1883
MQTT_USER_ID = 'kepco'
MQTT_USER_PW = '!kepco1234'
# #source
# RTSP = "rtsp://10.20.10.1:8554/cam/0/low"
# RTSP = "rtsp://192.168.39.20:8554/cam/0/low"
RTSP = "rtsp://admin:admin1263!@10.20.10.99:28554/onvif/media?profile=Profile2"
RTSP = "rtsp://admin:admin1263!@10.20.10.99:554/onvif/media?profile=Profile2"
CON_SOURCE = RTSP
FR_SOURCE = RTSP
PPE_SOURCE = RTSP
WD_SOURCE = RTSP
# ----------- <test> ----------
#CON_SOURCE = "rtsp://219.250.188.204:8554/con"
#FR_SOURCE = "rtsp://219.250.188.205:8554/fr"
#PPE_SOURCE = "rtsp://219.250.188.206:8554/ppe"
#WD_SOURCE = "rtsp://219.250.188.207:8554/wd"
# CON_SOURCE = "rtsp://219.250.188.204:8554/con"
# FR_SOURCE = "rtsp://219.250.188.205:8554/fr"
# PPE_SOURCE = "rtsp://219.250.188.206:8554/ppe"
# WD_SOURCE = "rtsp://219.250.188.207:8554/wd"
# ----------- <test> ----------
if project_config.DEBUG_MODE:
@@ -162,6 +162,10 @@ WORKER1_IMG_PATH = PROJECT_PATH + "/AI_ENGINE/DATA/kepco1.jpg"
WORKER2_IMG_PATH = PROJECT_PATH + "/AI_ENGINE/DATA/kepco1_1.jpg"
WORKER3_IMG_PATH = PROJECT_PATH + "/AI_ENGINE/DATA/kepco1_2.jpg"
WORKER1_IMG_PATH = PROJECT_PATH + "/AI_ENGINE/DATA/facerec_worker1.png"
WORKER2_IMG_PATH = PROJECT_PATH + "/AI_ENGINE/DATA/facerec_worker2.png"
WORKER3_IMG_PATH = PROJECT_PATH + "/AI_ENGINE/DATA/facerec_worker3.png"
if project_config.DEBUG_MODE:
WORKER1_IMG_PATH = PROJECT_PATH + "/AI_ENGINE/DATA/facerec_worker1.png"
WORKER2_IMG_PATH = PROJECT_PATH + "/AI_ENGINE/DATA/facerec_worker2.png"
@@ -191,7 +195,7 @@ WORKER22_IMG_PATH = PROJECT_PATH + "/AI_ENGINE/DATA/kepco2_13.jpg"
# WORKER16_IMG_PATH = PROJECT_PATH + "/AI_ENGINE/DATA/yunikim.jpg"
# WORKER17_IMG_PATH = PROJECT_PATH + "/AI_ENGINE/DATA/facerec_worker3.png"
WORKER100_IMG_PATH = PROJECT_PATH + "/AI_ENGINE/DATA/facerec_worker3.png"
SIGNAL_INFERENCE = 'inference'
SIGNAL_STOP = 'stop'

View File

@@ -23,5 +23,4 @@ from REST_AI_ENGINE_CONTROL.app.common.config import conf
if __name__ == '__main__':
print('main.py run')
# os.system(". ./rtsp_start.sh")
uvicorn.run('REST_AI_ENGINE_CONTROL.app.main:app', host='0.0.0.0', port=conf().REST_SERVER_PORT, reload=True)

View File

@@ -34,7 +34,7 @@ def _bi_sftp_upload():
remotepath = "/home/agics-dev/kepri_storage/rndpartners/" + os.sep + "remote" + '.jpg'
#sftp.put(LOCAL_PATH, remotepath)
sftp.put(LOCAL_PATH, remotepath)
sftp.close()
transprot.close()

16
main.py
View File

@@ -1,16 +0,0 @@
# 샘플 Python 스크립트입니다.
# Ctrl+F5을(를) 눌러 실행하거나 내 코드로 바꿉니다.
# 클래스, 파일, 도구 창, 액션 및 설정을 어디서나 검색하려면 Shift 두 번을(를) 누릅니다.
def print_hi(name):
# 스크립트를 디버그하려면 하단 코드 줄의 중단점을 사용합니다.
print(f'Hi, {name}') # 중단점을 전환하려면 F9을(를) 누릅니다.
# 스크립트를 실행하려면 여백의 녹색 버튼을 누릅니다.
if __name__ == '__main__':
print_hi('PyCharm')
# https://www.jetbrains.com/help/pycharm/에서 PyCharm 도움말 참조

View File

@@ -10,6 +10,6 @@ CONFIG = CONFIG_MG
DEBUG_MODE = False
SFTP_UPLOAD = False
SFTP_UPLOAD = True
FR_UPLOAD = True
FR_UPLOAD = True

View File

@@ -1 +0,0 @@
mosquitto_pub -p 11883 -h localhost -t ptz -m 1,0.95,0 -u admin -P admin