I tried cv.SaveImage function to accomplish it, but I was getting some unexpected error saying that writer not found. Thanks in advance.
/* This is my sample code */
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()
Try to change cv.SaveImage('name',cv.Image);
into cv.SaveImage('name.jpg',cv.Image);
in the display_rgb method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.