2016-05-31 2 views
1

그것을 달성하기 위해 cv.SaveImage 함수를 시도했지만 작성자를 찾을 수 없다는 뜻밖의 오류가 발생했습니다. 미리 감사드립니다. 누구나 OpenCV를 사용하여 나무 딸기 파이에 kinect에서 RGB 이미지를 저장하는 방법을 설명 할 수 있습니까?

/* 이것은 내 샘플 코드 display_rgb 방법에 cv.SaveImage('name.jpg',cv.Image);cv.SaveImage('name',cv.Image);을 변경 */

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) 
+0

왜 'cv2'대신'cv'를 사용하고 있습니까? 'cv2.imwrite()'를 시도 했습니까? –

+0

예 cv2.imwrite()를 시도했지만 작동하지 않았습니다. – MazeRunner09

답변

0

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()