商业网站 模板,twenty ten wordpress,wordpress打开提速,数据分析网站怎么做OAK相机#xff1a;自动或手动设置相机参数 硬件软件 硬件
使用硬件如下#xff1a;
4✖️ov9782相机OAK-FFC-4P驱动板
硬件接线参考博主的一篇博客#xff1a;OAK相机#xff1a;多相机硬件同步拍摄 软件
博主使用的是Ubuntu18.04系统#xff0c;首先配置所需的pytho… OAK相机自动或手动设置相机参数 硬件软件 硬件
使用硬件如下
4✖️ov9782相机OAK-FFC-4P驱动板
硬件接线参考博主的一篇博客OAK相机多相机硬件同步拍摄 软件
博主使用的是Ubuntu18.04系统首先配置所需的python环境 1、下载SDK软件包
git clone https://gitee.com/oakchina/depthai.git2、安装依赖
python3 -m pip install -r depthai/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple3、注意在Linux平台并且第一次使用OAK需要配置udev规则
echo SUBSYSTEMusb, ATTRS{idVendor}03e7, MODE0666 | sudo tee /etc/udev/rules.d/80-movidius.rules
sudo udevadm control --reload-rules sudo udevadm trigger相关python API可参考官方文档https://docs.luxonis.com/projects/api/en/latest/references/python/# 在此博主提供一个示例四个相机通过硬件触发同步使用ROS发布图像消息并可以自动或手动设置相机参数更多设置可参考官方文档的API加以修改完整程序如下
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
import depthai as dai
import yaml
import cv2
assert cv2.__version__[0] 4, The fisheye module requires opencv version 3.0.0
import numpy as np
import globNAME_LIST [cama, camb, camc, camd]FPS 20
AUTOSET Truedef clamp(num, v0, v1):return max(v0, min(num, v1))class CameraArray:def __init__(self,fps20):self.FPS fpsself.RESOLUTION dai.ColorCameraProperties.SensorResolution.THE_800_Pself.cam_list [cam_a, cam_b, cam_c, cam_d]self.cam_socket_opts {cam_a: dai.CameraBoardSocket.CAM_A,cam_b: dai.CameraBoardSocket.CAM_B,cam_c: dai.CameraBoardSocket.CAM_C,cam_d: dai.CameraBoardSocket.CAM_D,}self.pipeline dai.Pipeline()self.cam {}self.xout {}# colorself.controlIn self.pipeline.create(dai.node.XLinkIn)self.controlIn.setStreamName(control)for camera_name in self.cam_list:self.cam[camera_name] self.pipeline.createColorCamera()self.cam[camera_name].setResolution(self.RESOLUTION)if camera_name cam_a: # ref triggerself.cam[camera_name].initialControl.setFrameSyncMode(dai.CameraControl.FrameSyncMode.OUTPUT)else: # other triggerself.cam[camera_name].initialControl.setFrameSyncMode(dai.CameraControl.FrameSyncMode.INPUT)self.cam[camera_name].setBoardSocket(self.cam_socket_opts[camera_name])self.xout[camera_name] self.pipeline.createXLinkOut()self.xout[camera_name].setStreamName(camera_name)self.cam[camera_name].isp.link(self.xout[camera_name].input)self.cam[camera_name].setFps(self.FPS)self.config dai.Device.Config()self.config.board.gpio[6] dai.BoardConfig.GPIO(dai.BoardConfig.GPIO.OUTPUT, dai.BoardConfig.GPIO.Level.HIGH)self.device dai.Device(self.config)def start(self):self.device.startPipeline(self.pipeline)self.output_queue_dict {}for camera_name in self.cam_list:self.output_queue_dict[camera_name] self.device.getOutputQueue(namecamera_name, maxSize1, blockingFalse)def read_data(self):output_img {}output_ts {}for camera_name in self.cam_list:output_data self.output_queue_dict[camera_name].tryGet()if output_data is not None:timestamp output_data.getTimestampDevice()img output_data.getCvFrame()# img cv2.rotate(img, cv2.ROTATE_180)output_img[camera_name] imgoutput_ts[camera_name] timestamp.total_seconds()# print(camera_name, timestamp, timestamp.microseconds, img.shape)else:# print(camera_name, No ouput)output_img[camera_name] Noneoutput_ts[camera_name] Nonereturn output_img, output_tsif __name__ __main__:import rospyfrom sensor_msgs.msg import Imagefrom std_msgs.msg import Headerclass CvBridge():def __init__(self):self.numpy_type_to_cvtype {uint8: 8U, int8: 8S, uint16: 16U,int16: 16S, int32: 32S, float32: 32F,float64: 64F}self.numpy_type_to_cvtype.update(dict((v, k) for (k, v) in self.numpy_type_to_cvtype.items()))def dtype_with_channels_to_cvtype2(self, dtype, n_channels):return %sC%d % (self.numpy_type_to_cvtype[dtype.name], n_channels)def cv2_to_imgmsg(self, cvim, encoding passthrough):img_msg Image()img_msg.height cvim.shape[0]img_msg.width cvim.shape[1]if len(cvim.shape) 3:cv_type self.dtype_with_channels_to_cvtype2(cvim.dtype, 1)else:cv_type self.dtype_with_channels_to_cvtype2(cvim.dtype, cvim.shape[2])if encoding passthrough:img_msg.encoding cv_typeelse:img_msg.encoding encodingif cvim.dtype.byteorder :img_msg.is_bigendian Trueimg_msg.data cvim.tobytes()img_msg.step len(img_msg.data) // img_msg.heightreturn img_msgbridge CvBridge()img_pub_dict {}rospy.init_node(camera_array, anonymousTrue)rate rospy.Rate(20)for camera_name in [cam_a, cam_b, cam_c, cam_d]:img_pub_dict[camera_name] rospy.Publisher(/img/str(camera_name), Image, queue_size0)img_cnt_dict {cam_a:0, cam_b:0, cam_c:0, cam_d:0}camera_array CameraArray(FPS)camera_array.start()controlQueue camera_array.device.getInputQueue(camera_array.controlIn.getStreamName())if AUTOSET:ctrl dai.CameraControl()ctrl.setAutoExposureEnable()ctrl.setAutoWhiteBalanceMode(dai.CameraControl.AutoWhiteBalanceMode.AUTO)controlQueue.send(ctrl)else:# Defaults and limits for manual focus/exposure controlsexpTime 10000expMin 1expMax 33000sensIso 100sensMin 100sensMax 1600wbManual 3500expTime clamp(expTime, expMin, expMax)sensIso clamp(sensIso, sensMin, sensMax)print(Setting manual exposure, time:, expTime, iso:, sensIso)ctrl dai.CameraControl()ctrl.setManualExposure(expTime, sensIso)ctrl.setManualWhiteBalance(wbManual)controlQueue.send(ctrl)first_time_cam Nonefirst_time_local Nonewhile not rospy.is_shutdown():output_img, output_ts camera_array.read_data()if first_time_cam is None and output_ts[cam_a] is not None:first_time_cam output_ts[cam_a]first_time_local rospy.Time.now().to_sec()for key in output_img.keys():if output_img[key] is None:continueframe output_img[key]# convertimg bridge.cv2_to_imgmsg(undistorted_img, encodingbgr8)img.header Header()if first_time_cam is not None:ts output_ts[key] - first_time_cam first_time_localimg.header.stamp rospy.Time.from_sec(ts)else:img.header.stamp rospy.Time.now()img_pub_dict[key].publish(img)rate.sleep()将程序拷贝到本地运行程序python camera.py输入rostopic list查看话题名打开Rviz查看图像输出。 文章转载自: http://www.morning.ruyuaixuexi.com.gov.cn.ruyuaixuexi.com http://www.morning.lqgtx.cn.gov.cn.lqgtx.cn http://www.morning.jphxt.cn.gov.cn.jphxt.cn http://www.morning.jklns.cn.gov.cn.jklns.cn http://www.morning.rythy.cn.gov.cn.rythy.cn http://www.morning.pbgnx.cn.gov.cn.pbgnx.cn http://www.morning.jbxfm.cn.gov.cn.jbxfm.cn http://www.morning.fqqcd.cn.gov.cn.fqqcd.cn http://www.morning.wphzr.cn.gov.cn.wphzr.cn http://www.morning.slmbg.cn.gov.cn.slmbg.cn http://www.morning.qctsd.cn.gov.cn.qctsd.cn http://www.morning.kljhr.cn.gov.cn.kljhr.cn http://www.morning.pngdc.cn.gov.cn.pngdc.cn http://www.morning.qrqg.cn.gov.cn.qrqg.cn http://www.morning.qtwd.cn.gov.cn.qtwd.cn http://www.morning.yrjfb.cn.gov.cn.yrjfb.cn http://www.morning.jzlfq.cn.gov.cn.jzlfq.cn http://www.morning.smtrp.cn.gov.cn.smtrp.cn http://www.morning.c7495.cn.gov.cn.c7495.cn http://www.morning.hmjasw.com.gov.cn.hmjasw.com http://www.morning.rzcmn.cn.gov.cn.rzcmn.cn http://www.morning.jhxdj.cn.gov.cn.jhxdj.cn http://www.morning.ltdxq.cn.gov.cn.ltdxq.cn http://www.morning.gryzk.cn.gov.cn.gryzk.cn http://www.morning.znmwb.cn.gov.cn.znmwb.cn http://www.morning.blznh.cn.gov.cn.blznh.cn http://www.morning.ckxd.cn.gov.cn.ckxd.cn http://www.morning.qwfl.cn.gov.cn.qwfl.cn http://www.morning.qfkdt.cn.gov.cn.qfkdt.cn http://www.morning.kqpq.cn.gov.cn.kqpq.cn http://www.morning.dmrjx.cn.gov.cn.dmrjx.cn http://www.morning.jcxzq.cn.gov.cn.jcxzq.cn http://www.morning.ydfr.cn.gov.cn.ydfr.cn http://www.morning.mdgpp.cn.gov.cn.mdgpp.cn http://www.morning.qggcc.cn.gov.cn.qggcc.cn http://www.morning.nxdqz.cn.gov.cn.nxdqz.cn http://www.morning.rytps.cn.gov.cn.rytps.cn http://www.morning.rnzjc.cn.gov.cn.rnzjc.cn http://www.morning.xwlmg.cn.gov.cn.xwlmg.cn http://www.morning.kxryg.cn.gov.cn.kxryg.cn http://www.morning.mnmrx.cn.gov.cn.mnmrx.cn http://www.morning.hjlwt.cn.gov.cn.hjlwt.cn http://www.morning.xhgxd.cn.gov.cn.xhgxd.cn http://www.morning.whpsl.cn.gov.cn.whpsl.cn http://www.morning.dbfwq.cn.gov.cn.dbfwq.cn http://www.morning.dlurfdo.cn.gov.cn.dlurfdo.cn http://www.morning.dqgbx.cn.gov.cn.dqgbx.cn http://www.morning.woyoua.com.gov.cn.woyoua.com http://www.morning.pxwzk.cn.gov.cn.pxwzk.cn http://www.morning.qfths.cn.gov.cn.qfths.cn http://www.morning.iiunion.com.gov.cn.iiunion.com http://www.morning.qfqld.cn.gov.cn.qfqld.cn http://www.morning.dyfmh.cn.gov.cn.dyfmh.cn http://www.morning.wlqbr.cn.gov.cn.wlqbr.cn http://www.morning.hslgq.cn.gov.cn.hslgq.cn http://www.morning.ghpld.cn.gov.cn.ghpld.cn http://www.morning.wklmj.cn.gov.cn.wklmj.cn http://www.morning.ctlbf.cn.gov.cn.ctlbf.cn http://www.morning.wmmjw.cn.gov.cn.wmmjw.cn http://www.morning.gwmny.cn.gov.cn.gwmny.cn http://www.morning.rkqzx.cn.gov.cn.rkqzx.cn http://www.morning.yrddl.cn.gov.cn.yrddl.cn http://www.morning.hpkr.cn.gov.cn.hpkr.cn http://www.morning.jljwk.cn.gov.cn.jljwk.cn http://www.morning.fhkr.cn.gov.cn.fhkr.cn http://www.morning.xnbd.cn.gov.cn.xnbd.cn http://www.morning.ynbyk.cn.gov.cn.ynbyk.cn http://www.morning.kbqws.cn.gov.cn.kbqws.cn http://www.morning.jhxtm.cn.gov.cn.jhxtm.cn http://www.morning.mmjqk.cn.gov.cn.mmjqk.cn http://www.morning.gcspr.cn.gov.cn.gcspr.cn http://www.morning.baohum.com.gov.cn.baohum.com http://www.morning.kwdfn.cn.gov.cn.kwdfn.cn http://www.morning.hpkr.cn.gov.cn.hpkr.cn http://www.morning.sqfnx.cn.gov.cn.sqfnx.cn http://www.morning.rqqkc.cn.gov.cn.rqqkc.cn http://www.morning.snkry.cn.gov.cn.snkry.cn http://www.morning.qytyt.cn.gov.cn.qytyt.cn http://www.morning.gwkjg.cn.gov.cn.gwkjg.cn http://www.morning.xkpjl.cn.gov.cn.xkpjl.cn