Python:3.9.9,本 Python 环境为 Windows 下的 Scoop 包管理工具安装版本
然后是涉及到的 Python 库:
实验所需要的所有 Python 库。如下。
opencv-python
numpy
imutils
Imutils are a series of convenience functions to make basic image processing functions such as translation, rotation, resizing, skeletonization, and displaying Matplotlib images easier with OpenCV and both Python 2.7 and Python 3.
dlib
这是一个包含机器学习算法和工具的库。安装这个需要 PC 上有 Visual Studio for C++.
detector.setInput(blob) person_detections = detector.forward() rects = [] for i in np.arange(0, person_detections.shape[2]): confidence = person_detections[0, 0, i, 2] if confidence > 0.5: idx = int(person_detections[0, 0, i, 1])
cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 0, 255), 2) # tag a person with a unique ID text = "ID: {}".format(objectId) cv2.putText(frame, text, (x1, y1 - 22), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255), 1)
cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 0, 255), 2) # tag a person with a unique ID text = "ID: {}".format(objectId) cv2.putText(frame, text, (x1, y1 - 22), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255), 1) # detect and show the moving direction of a detected person direct_vector = (pre_coord_lists[index][1][0] - pre_coord_lists[index][0][0], pre_coord_lists[index][1][1] - pre_coord_lists[index][0][1]) direction_text = "direction: {}".format(direct_vector) cv2.putText(frame, direction_text, (x1, y1 - 5), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255), 1)
# a dictionary of all the hex and their respective names in css3 css3_db = CSS3_HEX_TO_NAMES names = [] rgb_values = [] for color_hex, color_name in css3_db.items(): names.append(color_name) rgb_values.append(hex_to_rgb(color_hex))
kdt_db = KDTree(rgb_values) distance, index = kdt_db.query(rgb_tuple) returnf'closest match: {names[index]}'