Apriltag:在Coppeliasim中无法通过视觉传感器/摄像头识别tag

原因在于Coppeliasim输出的图像时关于y轴镜像的,所以导致Apriltag无法识别
可以在视觉传感器的脚本使用simVision插件进行镜像

function sysCall_init()

    -- Get some handles:
    activeVisionSensor=sim.getObjectHandle('Vision_sensor')
    visionSensor=sim.getObjectAssociatedWithScript(sim.handle_self)
    -- Enable an image publisher and subscriber:
    if simROS then
    
        print("<font color='#0F0'>ROS interface was found.</font>@html")
        pub=simROS.advertise('/floorCamera', 'sensor_msgs/Image')
        simROS.publisherTreatUInt8ArrayAsString(pub) -- treat uint8 arrays as strings (much faster, tables/arrays are kind of slow in Lua)
        
    else
        print("<font color='#F00'>ROS interface was not found. Cannot run.</font>@html")
    end
end

function sysCall_sensing()
	--触发视觉处理回调函数
    local trigger,packet1,packet2=sim.handleVisionSensor(visionSensor)

    if simROS then
        --set /use_sim_time to true
        simROS.publish(clockpub,{clock=sim.getSystemTime()})
        -- Publish the image of the active vision sensor:
        local data,w,h=sim.getVisionSensorCharImage(activeVisionSensor)
        d={}
        d['header']={stamp=sim.getSystemTime(), frame_id="floorCamera_link"}
        d['height']=h
        d['width']=w
        d['encoding']='rgb8'
        d['is_bigendian']=1
        d['step']=w*3
        d['data']=data
        simROS.publish(pub,d)       
    end
end

function sysCall_cleanup()
    if simROS then
        -- Shut down publisher and subscriber. Not really needed from a simulation script (automatic shutdown)
        simROS.shutdownPublisher(pub)
    end
end

function sysCall_vision(inData)

    simVision.sensorImgToWorkImg(inData.handle)
    simVision.horizontalFlipWorkImg(inData.handle)
    simVision.workImgToSensorImg(inData.handle)

end


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用摄像头实时识别apriltag二维码并保存识别的数据,你可以使用Python的OpenCV库来实现。具体的步骤如下: 1. 安装OpenCV库。可以使用pip命令来安装:`pip install opencv-python` 2. 导入OpenCV库和apriltag库。apriltag库可以使用pip命令安装:`pip install apriltag` 3. 初始化摄像头。使用OpenCV库的VideoCapture类来打开摄像头。 4. 循环读取摄像头的每一帧图像,并进行apriltag二维码的识别。使用apriltag的Detector类来识别二维码。 5. 将识别得到的数据保存到文件。可以使用上面提到的方法来实现。 下面是一个示例代码,可以实现使用摄像头实时识别apriltag二维码并保存识别的数据: ```python import cv2 import apriltag import json # 初始化摄像头 cap = cv2.VideoCapture(0) # 初始化apriltag检测器 detector = apriltag.Detector() # 循环读取摄像头的每一帧图像 while True: ret, frame = cap.read() if ret: # 转换为灰度图像 gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # 使用apriltag检测器识别二维码 result = detector.detect(gray) # 将识别得到的数据保存到文件 with open('data.json', 'a') as f: for r in result: data = {'id': r.tag_id, 'data': r.tag_family.decode()} json.dump(data, f) f.write('\n') # 在图像上绘制识别结果 for r in result: (x, y, w, h) = r.corners.astype(int) cv2.polylines(frame, [r.corners.astype(int)], True, (0, 255, 0), 2) cv2.putText(frame, str(r.tag_id), (x, y), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2) # 显示图像 cv2.imshow('frame', frame) # 按下q键退出循环 if cv2.waitKey(1) & 0xFF == ord('q'): break # 释放摄像头并关闭窗口 cap.release() cv2.destroyAllWindows() ``` 在这个示例,我们使用了apriltag库的Detector类来识别二维码,并将识别得到的数据保存到data.json文件。使用cv2.imshow()函数可以实时显示摄像头的图像,并使用cv2.waitKey()函数来等待用户按下q键退出循环。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值