问题描述
我正在做一个项目,我必须在我的凉亭模拟中校准一个固定的相机。首先,生成一个图案,然后用我的固定相机拍一些照片,最后将这些照片发送到 matlab。
到目前为止,我已经生成了一个棋盘格图案,但是,我的下一步是更改此棋盘格方向(而不是位置)以拍摄不同的照片。
所以我的方法是在不同的位置和方向以某种方式产生这个模型(模式)的 10 倍。应该是这样的:
-初始化凉亭世界 - 生成模式 pos 1 -擦除这个图案 - 生成模式 pos 2 -擦除这个图案 -....
请问,我如何实现此代码才能满足我的需求??
Pd:我也愿意接受其他想法。
提前致谢和问候,
我该怎么做
编辑!!
我工作所以我设法创建了这个 .py
import rospy,tf,random,string
from random import randint,uniform
from gazebo_msgs.srv import DeleteModel,SpawnModel
from geometry_msgs.msg import *
import rospy
from sensor_msgs.msg import Image
from cv_bridge import CvBridge,CvBridgeError
import cv2
import os
import captura_patron as captura
bridge = CvBridge()
def image_callback(msg):
print("Received an image!")
try:
# Convert your ROS Image message to OpenCV2
cv2_img = bridge.imgmsg_to_cv2(msg,"bgr8")
except CvBridgeError,e:
print(e)
else:
# Save your OpenCV2 image as a jpeg
#cv2.imwrite(os.path.join(os.path.expanduser('~'),'home','ros-industrial','POPBL','src','python','patron.jpg'),cv2_img)
cv2.imwrite('camera_image.jpeg'+ str(count),cv2_img)
def capturador():
# Set up your subscriber and define its callback
rospy.Subscriber("camera/cal_image",Image,image_callback)
print("LIXTO")
# Spin until ctrl + c
if __name__ == '__main__':
print("Waiting for gazebo services...")
rospy.init_node("patron_spawn")
rospy.wait_for_service("gazebo/spawn_sdf_model")
print("Got it.")
spawn_patron = rospy.ServiceProxy("gazebo/spawn_sdf_model",SpawnModel)
srv_delete_model = rospy.ServiceProxy('gazebo/delete_model',DeleteModel)
with open("/home/ros-industrial/POPBL/src/PAP_TALLER/models/patron/model.sdf","r") as f:
Box = f.read()
count = 0
while count < 1000:
count = count + 1
choice = randint(1,3)
if choice == 1:
with open("/home/ros-industrial/POPBL/src/PAP_TALLER/models/patron/model.sdf","r") as f:
Box = f.read()
rospy.loginfo("Press any key to spawn a model")
raw_input()
Position = Pose()
orient = tf.transformations.quaternion_from_euler(0,0 + random.uniform(-1,1) )
Position.position.x = 1.3 + random.uniform(-0.1,0.1)
Position.position.y = -0.5 + random.uniform(-0.1,0.1)
Position.position.z = 0.8126
Position.orientation.x = orient[0]
Position.orientation.y = orient[1]
Position.orientation.z = orient[2]
Position.orientation.w = orient[3]
item_name = "patron" + str(count)
print("Spawning model:",item_name)
spawn_patron(item_name,Box,'',Position,"world")
rospy.sleep(1)
#execfile('captura_patron.py')
#captura.main()
capturador()
print("PHOTO SAVED")
rospy.sleep(1)
res = srv_delete_model(item_name)
现在这个模式产生了我想要的 10 个,但我有这个问题,保存在我目录中的图像总是“刷新”此外,每个循环只创建一个图像而不是一个图像。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)