浅谈嵌入式:opencv接收topic转换格式上传

编程入门 行业动态 更新时间:2024-10-07 04:33:25

<a href=https://www.elefans.com/category/jswz/34/1769825.html style=浅谈嵌入式:opencv接收topic转换格式上传"/>

浅谈嵌入式:opencv接收topic转换格式上传

 有些地方没有注释,上一篇文章可以找到,想学习的可以看看上一篇文章,偷懒的可以直接复制。

大家点个赞再走吧,敲代码不容易,欢迎白嫖。大家的支持就是我的动力。

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import cv2
import rospy
# import StringIO       # 缓冲区读取类  from sensor_msgs.msg import Image as RosImage
from cv_bridge import CvBridgeimport numpy as np
import cv2
import threading
from copy import deepcopyfrom std_msgs.msg import String
import ftplib
import time
bridge = CvBridge()ftp1 = ftplib.FTP()  #
ftp1.set_debuglevel(2)  # 
ftp1.connect("***.***.***.***", **)  
ftp1.login("**", "**")  
bufsize = 1024
ftp1.cwd("/usr/111/")
thread_lock = threading.Lock()    # 定义锁
thread_exit = Falsefo1 = open("Front1.jpeg","wb")
fo1.close()
class myThread(threading.Thread):def __init__(self,img,test,photo,photo1,STOR):threading.Thread.__init__(self)self.img=imgself.test=testself.photo=photoself.photo1=photo1self.STOR=STORdef run(self):# cap = cv2.VideoCapture(self.camera_id)print(1,time.time())       # cv2.imshow(self.name,self.n)if self.img is not None:# cv2.imwrite(self.photo, self.img)x, y=self.img.shape[0:2]self.test = cv2.resize(self.img,(int(y / 10),int(x / 10)))cv2.imwrite(self.photo1,self.test)print(2,time.time())# file_handle=open(self.photo1,"rb")# fo.close()# fo1.close()     # ftp1.storbinary(self.STOR,file_handle,1024)
class sendThread(threading.Thread):def __init__(ca,ftp,file,file_handle,photo,photo1,STOR):threading.Thread.__init__(ca)ca.ftp=ftpca.file=fileca.file_handle=file_handleca.photo=photoca.photo1=photo1ca.STOR=STORdef run(ca):if ca.photo1 is None:return # ca.file = ca.photo1print(3,time.time())thread_lock.acquire()# ca.file_handle = open(ca.file,"rb")print(3.5, time.time())# ftp1.storbinary(ca.STOR,ca.file_handle,1024)file_handle = open(ca.photo1,"rb")print(3.6, time.time())ftp1.storbinary(ca.STOR,file_handle,1024)thread_lock.release() fo1.close()print(4,time.time())
#  thread2.start()
class GroundDetect(object): # 接收topic 并进行格式转换model = Nonecounter = 0red = Nonedef __init__(self): rospy.Subscriber("/mynteye/left_rect/image_rect",RosImage, self.image_cb)passdef image_cb(self, ros_image: RosImage):time0 = time.time()# data = R.mget(# ["course_angle", "latitude", "longitde", "pathDir", "move_seven_list", "seven_list", "turn_yes_count",#  "road_angle_zhuan", "yiduan_angle"])time_stack=time.time() * 1000cv_image = bridge.imgmsg_to_cv2(ros_image)thread1 = myThread(cv_image,"img_test1","Front.jpeg","Front1.jpeg","STOR Front1.jpeg")  # 定义线程threadsend1 = sendThread("ftp1","file1","file_handle1","Front.jpeg","Front1.jpeg","STOR Front1.jpeg") # 定义线程thread1.start()  # 开启线程# time.sleep(10)threadsend1.start()if __name__ == '__main__':rospy.init_node("current_lane_node_25", anonymous=True)GroundDetect()rospy.spin()

更多推荐

浅谈嵌入式:opencv接收topic转换格式上传

本文发布于:2024-03-04 11:31:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1709157.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:浅谈   嵌入式   上传   格式   opencv

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!