[英]How to capture and save images from two USB cameras connected to a Raspberry Pi 3 simultaneously using OpenCV?
[英]Could anyone explain how to save RGB image from kinect on Raspberry Pi using OpenCV?
我尝试使用cv.SaveImage函数来完成此操作,但是却遇到了一些意外错误,指出找不到作者。 提前致谢。
/ *这是我的示例代码* /
import freenect
import cv
import frame_convert
import time
import cv2
import numpy as np
cv.NamedWindow('Depth')
cv.NamedWindow('RGB')
keep_running = True
def display_depth(dev, data, timestamp):
global keep_running
cv.ShowImage('Depth', frame_convert.pretty_depth_cv(data))
#time.sleep(1)
if cv.WaitKey(10) == 27:
keep_running = False
def display_rgb(dev, data, timestamp):
global keep_running
cv.Image= frame_convert.video_cv(data)
img = cv.CreateImage(cv.GetSize(cv.Image), cv.IPL_DEPTH_16S, 3)
cv.ShowImage('RGB',cv.Image)
for x in range(1,5):
name= "img%d" %(x)
cv.SaveImage('name',cv.Image);
time.sleep(1)
if cv.WaitKey(10) == 27:
keep_running = False
def body(*args):
if not keep_running:
raise freenect.Kill
print('Streaming from Kinnect... Please wait...Press ESC in window to stop')
freenect.runloop(depth=display_depth,
video=display_rgb,
body=body)
#import the necessary modules
import freenect
import cv2
import numpy as np
#function to get RGB image from kinect
def get_video():
array,_ = freenect.sync_get_video()
array = cv2.cvtColor(array,cv2.COLOR_RGB2BGR)
return array
#function to get depth image from kinect
def get_depth():
array,_ = freenect.sync_get_depth()
array = array.astype(np.uint8)
return array
if __name__ == "__main__":
i = 0
while 1:
#get a frame from RGB camera
frame = get_video()
#get a frame from depth sensor
depth = get_depth()
#display RGB image
cv2.imshow('RGB image',frame)
#display depth image
cv2.imshow('Depth image',depth)
k = cv2.waitKey(5) & 0xFF
if k == 27: # wait for ESC key to exit
cv2.destroyAllWindows()
elif k == ord('s'): # wait for 's' key to save and exit
cv2.imwrite('frame'+str(i)+'.png',frame)
cv2.imwrite('depth'+str(i)+'.png',depth)
i = i+1
cv2.destroyAllWindows()
尝试更改cv.SaveImage('name',cv.Image);
进入cv.SaveImage('name.jpg',cv.Image);
在display_rgb方法中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.