我尝试使用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)
最佳答案
使用cv2.imwrite非常容易。在这里,我已将RGB和深度数据保存为.png格式的图像,但是您可以将其更改为所需的任何格式。
希望能帮助到你。
#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()
关于python - 谁能解释如何使用OpenCV在Raspberry Pi上从kinect保存RGB图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37552919/