ROS melodic with python3得到openCV错误



如标题所述,我试图使用ros melodic与python3。第一个错误弹出,因为cv_bridge,它已被修复。现在我得到这个错误:

[ERROR] [1673464074.204372, 2767.036000]: bad callback: <function im_callback at 0x7f889d1aed90>
cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-civioau0/opencv/modules/dnn/src/tensorflow/tf_importer.cpp:586:
error: (-2:Unspecified error) Const input blob for weights not found in function 'getConstBlob'

我检查了,没有找到任何关于这个错误的信息。

这是我的代码,我试图重新运行:

#! /usr/bin/env python3
import cv2 
import numpy as np
import rospy
import sensor_msgs.msg as sensor
import cv_bridge
rostopic = "/iris/camera/rgb/image_raw"
rosmsg = sensor.Image
configPath = "/home/irene/catkin_ws/src/beginner_tutorials/scripts/model/ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt" #file.pbtxt
modelPath = "/home/irene/catkin_ws/src/beginner_tutorials/scripts/model/frozen_inference_graph.pb" #file.pb
classesPath = "/home/irene/catkin_ws/src/beginner_tutorials/scripts/model/coco.names" #file.names
bridge = cv_bridge.CvBridge()
def im_callback(rosmsg):
global configPath, modelPath, classesPath, bridge
img = bridge.imgmsg_to_cv2(rosmsg, "bgr8")
net = cv2.dnn_DetectionModel(modelPath, configPath)
net.setInputSize(320,320)
net.setInputScale(1/127.5)
net.setInputMean((127.5, 127.5, 127.5))
net.setInputSwapRB(True)
with open(classesPath, "r") as file:
classesList = file.read().splitlines()
classesLabelIDs, confidences, body_rects = net.detect(img, confThreshold = 0.6)
body_rects = list(body_rects)
confidences = list(np.array(confidences).reshape(1,-1)[0])
confidences = list(map(float, confidences))
bboxsIDx = cv2.dnn.NMSBoxes(body_rects, confidences, score_threshold=0.5, nms_threshold = 0.2) 
if len(bboxsIDx) != 0:
for _, bID in enumerate(bboxsIDx):
classLabelID = np.squeeze(classesLabelIDs[np.squeeze(bID)])
classLabel = classesList[classLabelID]
if classLabel == "person":
body_rect = body_rects[np.squeeze(bID)]
classConfidence = confidences[np.squeeze(bID)]
display_text = "{} - {:.1}".format(classLabel, classConfidence)
x,y,w,h = body_rect

cv2.rectangle(img, (x,y), (x+w, y+h), (0,0,255), 1)
cv2.line(img, (x,y), (x+ int(w*.3), y), (0,0,255), 3)
cv2.line(img, (x,y), (x, y + int(h*.3)), (0,0,255), 3)
cv2.line(img, (x+w,y), (x + w - int(w*.3), y), (0,0,255), 3)
cv2.line(img, (x+w,y), (x+w, y + int(h*.3)), (0,0,255), 3)
cv2.line(img, (x+w,y+h), (x + w - int(w*.3), y + h), (0,0,255), 3)
cv2.line(img, (x+w,y+h), (x+w, y + h - int(h*.3)), (0,0,255), 3)
cv2.line(img, (x,y+h), (x + int(w*.3), y+h), (0,0,255), 3)
cv2.line(img, (x,y+h), (x, y + h -int(h*.3)), (0,0,255), 3)
cv2.putText(img, display_text, (x, y-8), cv2.FONT_HERSHEY_COMPLEX, .4, (255,255,255), 1)
cv2.imshow("Image", img)
cv2.waitKey(1)
def main():
global rosmsg, rostopic

rospy.init_node("webcam_node", anonymous=True)

rospy.Subscriber(rostopic, rosmsg, im_callback)
rospy.spin()


if __name__ == "__main__":
main()

我试图使用ROS melodic与python3,我得到了这个错误

您可能已经猜到,这个错误是因为您试图使用Python3。Melodic专门针对Python2.7,由于您看到的原因,强烈不建议尝试让它与Python3一起运行。如果你真的想在你的项目中使用Python3包和依赖项,你应该运行ROS的Noetic发行版。

相关内容

最新更新