1.摄像头图读取数据
2.设置默认参数调用
3.python3多进程实现
1.摄像头图读取数据
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import v4l2capture
import select
from ctypes import *
import struct, array
from fcntl import ioctl
import cv2
import numpy as np
import time
from sys import argv
import multiprocessing
import time
import getopt
path = os.path.split(os.path.realpath(__file__))[0]+"/.."
save_name="img"
def save_image_process(Camera):
video = v4l2capture.Video_device(Camera)
video.set_format(424,240, fourcc='MJPG')
video.create_buffers(1)
video.queue_all_buffers()
video.start()
imgInd = 0
while 1:
select.select((video,), (), ())
image_data = video.read_and_queue()
frame = cv2.imdecode(np.frombuffer(image_data, dtype=np.uint8), cv2.IMREAD_COLOR)
cv2.imshow('video',frame)
cv2.imwrite(path+"/data/"+save_name+"/{}.jpg".format(imgInd), frame)
#a.value = imgInd
print("imgInd=",imgInd)
imgInd+=1
time.sleep(0.05)
key = cv2.waitKey(1)
if key & 0xFF == ord('q'):
break
if __name__ == '__main__':
save_image_process("/dev/video0")
2.设置默认参数调用
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import v4l2capture
import select
from ctypes import *
import struct, array
from fcntl import ioctl
import cv2
import numpy as np
import time
from sys import argv
import multiprocessing
import time
import getopt
camera.value = "/dev/video0"
output_data.value = "data"
Speed[0] = 1560
Speed[1] = 1500
serial.value = "/dev/ttyUSB0"
save_name="img"
for opt_name,opt_value in opts:
if opt_name in ('-h','-H'):
print("python3 Data_Coll.py --vels=1560 --output=data --serial=/dev/ttyUSB0 --camera=/dev/video0 --save_name=img ")
exit()
if opt_name in ('--vels'):
Speed[0] = int(opt_value)
if opt_name in ('--output'):
output_data.value = opt_value
if opt_name in ('--serial'):
serial.value = opt_value
if opt_name in ('--camera'):
camera.value = opt_value
print("camera.value=",camera.value)
if opt_name in ('--save_name'):
save_name = opt_value
print("save_name=",save_name)


被折叠的 条评论
为什么被折叠?



