Skip to content

Commit

Permalink
注释
Browse files Browse the repository at this point in the history
  • Loading branch information
Timthony committed Sep 29, 2018
1 parent 43d8c53 commit f23b637
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 11 deletions.
Binary file modified .DS_Store
Binary file not shown.
24 changes: 14 additions & 10 deletions collect_data (1).py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# 收集数据,赛道照片和对应的前、后、左、右、停
# 对应图片和相应的标签值
import io
import car_control
import os
os.environ['SDL_VIDEODRIVE'] = 'x11'
import pygame
import pygame # 检测模块
from time import ctime,sleep,time
import threading
import numpy as np
Expand All @@ -16,19 +18,20 @@ class SplitFrames(object):
def __init__(self):
self.frame_num = 0
self.output = None

# 处理图像的函数write
# 对视频拍摄的每一帧进行处理,构造一个自定义输出类,每拍摄一帧都会进来write处理
def write(self, buf):
global key
if buf.startswith(b'\xff\xd8'):
if buf.startswith(b'\xff\xd8'): # 代表一个JPG图片的开始,新照片的开头
# Start of new frame; close the old one (if any) and
# open a new output
if self.output:
self.output.close()
self.frame_num += 1
self.output = io.open('%s_image%s.jpg' % (key,time()), 'wb')
self.output = io.open('%s_image%s.jpg' % (key,time()), 'wb') # 改变格式为jpg
self.output.write(buf)


def pi_capture():
global train_img, is_capture_running,train_labels,key

Expand Down Expand Up @@ -58,20 +61,21 @@ def my_car_control():
global is_capture_running, key
key = 4
pygame.init()
pygame.display.set_mode((1,1))
pygame.display.set_mode((1,1)) # 窗口
car_control.car_stop()
sleep(0.1)
print("Start control!")

while is_capture_running:
# get input from human driver
#
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
key_input = pygame.key.get_pressed()
if event.type == pygame.KEYDOWN: # 判断事件是不是按键按下的事件
key_input = pygame.key.get_pressed() # 可以同时检测多个按键
print(key_input[pygame.K_w], key_input[pygame.K_a], key_input[pygame.K_d])
if key_input[pygame.K_w] and not key_input[pygame.K_a] and not key_input[pygame.K_d]:
print("Forward")
key = 2
key = 2
car_control.car_move_forward()
elif key_input[pygame.K_a]:
print("Left")
Expand Down Expand Up @@ -111,7 +115,7 @@ def my_car_control():

print("capture thread")
print ('-' * 50)
capture_thread = threading.Thread(target=pi_capture,args=())
capture_thread = threading.Thread(target=pi_capture,args=()) # 开启线程
capture_thread.setDaemon(True)
capture_thread.start()

Expand Down
50 changes: 50 additions & 0 deletions collectdata_zth
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import io
import os
import threading
import time
import picamera


class SplitFrames(object):
def __init__(self):
self.frame_num = 0
self.output = 0
# 处理图像的函数write,实时保存每一张照片
# 对视频拍摄的每一帧进行处理,构造一个自定义输出类,每拍摄一帧都会进来write处理
def write(self, buf):
global key
if buf.startswith(b'\xff\xd8'): # 代表一个JPG图片的开始,新照片的开头
if self.output:
self.output.close()
self.frame_num += 1
self.output = io.open('%s_image%s.jpg' % (key, time()), 'wb') # 打开
self.output.write(buf)



while True:


# 多线程处理照片

#with picamera.Picamera(resolution=('160, 120')) as camera:
#pass



















2 changes: 1 addition & 1 deletion drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def run(self):
image_np = np.array(image)
camera_data_array = np.expand_dims(image_np,axis = 0)
current_time = time.time()
if current_time>latest_time:
if current_time > latest_time:
if current_time-latest_time>1:
print("*" * 30)
print(current_time-latest_time)
Expand Down

0 comments on commit f23b637

Please sign in to comment.