1

キーを押したときに Web カメラから画像を保存しようとしていますが、機能していません。ここに私のコードを添付します:

import cv

cv.NamedWindow("w1", cv.CV_WINDOW_AUTOSIZE)
camera_index = 0
capture = cv.CaptureFromCAM(camera_index)
i=0

def repeat():
 global capture 
 global camera_index
 frame = cv.QueryFrame(capture)
 cv.ShowImage("w1", frame)
 c = cv.WaitKey(25)
 if(c=="n"): 
  cv.SaveImage("f"+str(i)+".jpg",frame) 
  i=i+1
while True:
    repeat()
4

3 に答える 3

1

cv.WaitKey() はキーを返しませんが、タイムアウト時に -1 を返します。

以下で解決:

import cv

cv.NamedWindow("w1", cv.CV_WINDOW_AUTOSIZE)
camera_index = 0
capture = cv.CaptureFromCAM(camera_index)
i=0

def repeat():
 global capture 
 global camera_index
 frame = cv.QueryFrame(capture)
 cv.ShowImage("w1", frame)
 c = cv.WaitKey(25)
 if (c != -1): 
  cv.SaveImage("f"+str(i)+".jpg",frame) 
  i=i+1
while True:
    repeat()
于 2013-10-18T11:53:56.617 に答える
0

's'を押すだけで画像を保存できます。以下は C++ の例です。

単純にこのようにします

char ch =  cvWaitKey(25);  // Wait for 25 ms for user to hit any key

  // Save image if s was keyboard
  if(ch=='s')
  {
     cvSaveImage(path,small);
  }
  if(ch==27) break;  // If Escape Key was hit just exit the loop

お役に立てれば。:)

于 2017-01-07T11:31:36.340 に答える