msg MQTT message

main
zart 1 year ago
parent febf2cf2ce
commit d3843c8499

@ -30,7 +30,7 @@ def on_message(client, userdata, msg):
print("收到响应: "+str(msg.topic) + str(msg.payload))
if msg.topic == "image/{}".format(user_id):
with open("image/image.jpg", "wb") as f:
with open("edu_coder/step3/images/source/image.jpg", "wb") as f:
f.write(msg.payload)
print("图片已保存。")

@ -0,0 +1,54 @@
# coding:utf-8
import cv2
import matplotlib.pyplot as plt
import os
_currentFilePath = os.path.split(os.path.realpath(__file__))[0]
#opencv人脸检测分类器可以进行更换请根据左侧分类器选择你想用的填写其中
############### Begin #############
classifierFileName = "haarcascade_frontalface_alt.xml"
face_cascade = cv2.CascadeClassifier(os.path.join(_currentFilePath, classifierFileName))
############### End #############
# 读取图片
def read_directory(directory_name):
_cnt = 0
for filename in os.listdir(directory_name):
if filename.lower().endswith(".png") is False and filename.lower().endswith(".jpg") is False:
continue
_pathToFile = directory_name + "/" + filename
image = cv2.imread(_pathToFile)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# 探测图片中的人脸
faces = face_cascade.detectMultiScale(
gray,
scaleFactor=1.15,
minNeighbors=5,
minSize=(5, 5),
flags=cv2.CASCADE_SCALE_IMAGE)
for (x, y, w, h) in faces:
cv2.rectangle(image,(x,y),(x+w,y+h),(0,255,0),2)#直接在源操作了
if len(faces) == 0:
print('未检测出人脸')
else:
_pathToSavedFile = os.path.join(_currentFilePath, "./images/result/") + filename + ".rst.jpg"
cv2.imwrite(_pathToSavedFile, image)
print("生成结果成功!", _pathToSavedFile)
print('检测到%d张人脸' % len(faces))
print('检测成功!')
_cnt = _cnt + 1
if _cnt == 0:
print("检测失败!")
read_directory(os.path.join(_currentFilePath, "images/source"))

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,18 @@
_stepPath=$(cd $(dirname $0); pwd)
echo $(dirname $0)
## 统计userfiles 是否成功读取到文件
shuliang=$(find /data/workspace/userfiles -iname "*.jpg" | wc -l)
if [ $shuliang -eq 0 ]; then
echo "没有检测到文件"
exit 0
fi
rm $_stepPath/images/source/*.jpg > /dev/null 2&>1
rm $_stepPath/images/result/*.jpg > /dev/null 2&>1
# cp /data/workspace/userfiles/*.jpg $_stepPath/images/source/ > /dev/null 2&>1 #检测失败?
cp /data/workspace/userfiles/*.jpg $_stepPath/images/source/ > /dev/null
python3 $_stepPath/detect.py
Loading…
Cancel
Save