解决Jetson Nano使用CSI摄像头在Darknet下实时检测绿屏

        前两天一直被darknet实时检测时摄像头显示绿屏所困扰,一直没有找到较好的方法,今天终于看到一篇博客给出的解决方案,就是输入比较麻烦,语句如下:

./darknet detector demo cfg/coco.data cfg/yolov4-tiny.cfg yolov4-tiny.weights "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=1280, height=720, format=NV12, framerate=30/1 ! nvvidconv  ! video/x-raw, width=1280, height=720, format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink"

        实时检测的Demo终于可以正常的运行了,帧率也有十几,还是有一些卡顿的。出运行时现CSI摄像头显示绿屏的小伙伴可以试一试,语句的说明可以看这篇博客。如果用的是USB摄像头的应该不太会碰到这个问题,可能是和摄像头传回的数据有关系,CSI传回的是原始的图像数据,没有经过处理可能和darknet需要的数据不太一样。jetson nano tx2 调用csi摄像头(解决摄像头蓝屏问题)_天天放羊的博客-CSDN博客_jetsonnano调用csi摄像头./darknet detector demo cfg/coco.data cfg/yolov3-tiny.cfg yolov3-tiny.weights "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=1280, height=720, format=NV12, framerate=30/1 ! nvvidconv flip-method=2 ! video/x-raw, width=1280, height=720, format=BGRx ! vhttps://blog.csdn.net/weixin_45392081/article/details/106882538

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
YOLO(You Only Look Once)是一种目标检测算法,可以实现实时的物体检测。如果你想要使用YOLO来调用摄像头并实现绿屏效果,可以按照以下步骤进行操作: 1. 安装YOLO:首先,你需要安装YOLO的相关库和依赖项。可以通过在终端中运行命令来安装YOLO: ``` pip install opencv-python pip install numpy ``` 2. 下载YOLO权重文件:YOLO算法需要预训练的权重文件来进行物体检测。你可以从YOLO官方网站下载相应的权重文件。 3. 编写代码:使用Python编写代码来调用摄像头并实现绿屏效果。以下是一个简单的示例代码: ```python import cv2 import numpy as np # 加载YOLO模型 net = cv2.dnn.readNet("yolov3.weights", "yolov3.cfg") # 加载类别标签 classes = [] with open("coco.names", "r") as f: classes = [line.strip() for line in f.readlines()] # 设置绿屏颜色范围 lower_green = np.array([0, 100, 0]) upper_green = np.array([100, 255, 100]) # 打开摄像头 cap = cv2.VideoCapture(0) while True: # 读取摄像头帧 ret, frame = cap.read() # 对帧进行目标检测 blob = cv2.dnn.blobFromImage(frame, 1/255, (416, 416), (0, 0, 0), True, crop=False) net.setInput(blob) outs = net.forward() # 解析检测结果 class_ids = [] confidences = [] boxes = [] for out in outs: for detection in out: scores = detection[5:] class_id = np.argmax(scores) confidence = scores[class_id] if confidence > 0.5: center_x = int(detection * frame.shape) center_y = int(detection * frame.shape) width = int(detection * frame.shape) height = int(detection * frame.shape) left = int(center_x - width / 2) top = int(center_y - height / 2) class_ids.append(class_id) confidences.append(float(confidence)) boxes.append([left, top, width, height]) # 非最大抑制 indices = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4) # 绘制边界框和类别标签 for i in indices: i = i box = boxes[i] left = box top = box width = box height = box label = str(classes[class_ids[i]]) cv2.rectangle(frame, (left, top), (left + width, top + height), (0, 255, 0), 2) cv2.putText(frame, label, (left, top - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) # 绿屏效果 hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) mask = cv2.inRange(hsv, lower_green, upper_green) result = cv2.bitwise_and(frame, frame, mask=mask) # 显示结果 cv2.imshow("YOLO Green Screen", result) # 按下q键退出 if cv2.waitKey(1) & 0xFF == ord('q'): break # 释放摄像头和窗口 cap.release() cv2.destroyAllWindows() ``` 4. 运行代码:保存上述代码为一个Python文件,然后在终端中运行该文件。你将能够看到摄像头捕捉到的画面,并且检测到的物体会用绿色的边框标记出来。 希望以上步骤对你有所帮助!如果你有任何其他问题,请随时提问。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值