現在、私のラップトップのウェブカムフィードをVideoCapture cap(0)関数を使って取得して、Matフレームに表示しています。次に、キー「c」を押すたびに、フレームのスクリーンショットがJPEG画像としてフォルダに保存されます。しかし、私はそうする方法を知らない。ヘルプが必要です。ありがとうございます。OpenCVとC++を使用してKeypressのウェブカメラフィードのスクリーンショットを撮る
0
A
答えて
1
私は単純なキーボード入力で適切な解決策をインターネットで検索しました。 Therは、cv :: waitKeyを使用している間は、いつも足/遅れていました。
私が見つけた解決策は、Webカメラからフレームをキャプチャした直後にSleep(5)を追加することです。
以下の例は、異なるフォーラムスレッドの組み合わせです。
脚や遅延なしで動作します。 Windows OS。
"q"を押して、フレームをキャプチャして保存します。
常にウェブカムフィードがあります。シーケンスを変更して、キャプチャされたフレーム/イメージを表示することができます。
PS「tipka」 - キーボードの「キー」を意味します。このスレッドはあなたを助けることができるかもしれ
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdio.h>
#include <windows.h> // For Sleep
using namespace cv;
using namespace std;
int ct = 0;
char tipka;
char filename[100]; // For filename
int c = 1; // For filename
int main(int, char**)
{
Mat frame;
//--- INITIALIZE VIDEOCAPTURE
VideoCapture cap;
// open the default camera using default API
cap.open(0);
// OR advance usage: select any API backend
int deviceID = 0; // 0 = open default camera
int apiID = cv::CAP_ANY; // 0 = autodetect default API
// open selected camera using selected API
cap.open(deviceID + apiID);
// check if we succeeded
if (!cap.isOpened()) {
cerr << "ERROR! Unable to open camera\n";
return -1;
}
//--- GRAB AND WRITE LOOP
cout << "Start grabbing" << endl
<< "Press a to terminate" << endl;
for (;;)
{
// wait for a new frame from camera and store it into 'frame'
cap.read(frame);
if (frame.empty()) {
cerr << "ERROR! blank frame grabbed\n";
break;
}
Sleep(5); // Sleep is mandatory - for no leg!
// show live and wait for a key with timeout long enough to show images
imshow("CAMERA 1", frame); // Window name
tipka = cv::waitKey(30);
if (tipka == 'q') {
sprintf_s(filename, "C:/Images/Frame_%d.jpg", c); // select your folder - filename is "Frame_n"
cv::waitKey(10);
imshow("CAMERA 1", frame);
imwrite(filename, frame);
cout << "Frame_" << c << endl;
c++;
}
if (tipka == 'a') {
cout << "Terminating..." << endl;
Sleep(2000);
break;
}
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
関連する問題
- 1. コードを使用してスクリーンショットを撮る
- 2. クロム拡張用のjavascriptを使用してスクリーンショットを撮る
- 3. C#を使用して任意の外部アプリケーションのスクリーンショットを撮る
- 4. スクリーンショットを撮ると私はスクリーンショットのためのコードの下に使用し、アンドロイド
- 5. screenshotプラグインを使用してionic/cordovaのボタンでスクリーンショットを撮る
- 6. 150%のスケーリングでGraphics.CopyFromScreenを使用してスクリーンショットを撮る
- 7. javaを使用してウェブページのスクリーンショットを撮る
- 8. コンソールアプリケーションのVFramesを使用してウェブカメラでスクリーンショットを撮る
- 9. URLを使用してWebページのスクリーンショットを撮る
- 10. スクリーンショットを撮る
- 11. CocoaまたはC++を使用してMac OS Xでスクリーンショットを撮る方法
- 12. Robot Frameworkを使用してスクリーンショットを撮る方法
- 13. WebdriverでSeleniumを使用したFlashオブジェクトのスクリーンショットを撮る
- 14. フルスクリーンのスクリーンショットを撮るiOS
- 15. オーディオストリームのスクリーンショットを撮る
- 16. PCをスローダウンせずにスクリーンショットを連続して撮る - C#
- 17. IE8でC#を使ってSelenium RCを使ってスクリーンショットを撮るには?
- 18. Selenium WebDriversを使用して読み込み中にページのスクリーンショットを撮る
- 19. ウィンドウズストアアプリでスクリーンショットを撮る
- 20. Xcodeでスクリーンショットを撮る
- 21. Pythonでスクリーンショットを撮る - クロスプラットフォーム
- 22. スクリーンショットを撮るには?
- 23. PILでスクリーンショットを撮る
- 24. ffmpegを使ってスクリーンショットを撮るのはなぜですか?
- 25. PythonでSelenium Marionetteを使ってページ全体のスクリーンショットを撮る
- 26. PHPを使ってWebページのスクリーンショットを撮る方法は?
- 27. golangを使ってウェブサイトのスクリーンショットを撮るには?
- 28. C#の画面の特定のセクションのスクリーンショットを撮る?
- 29. Appuim - ロングプレスと同時にスクリーンショットを撮る
- 30. C#を使用してSeleniumでスクリーンショットを撮るには、この方法に問題がありますか?
よろしく、アンドレイ。 OPのコードが動作するはずです(彼は単にVisual Studioでいくつかの問題を抱えていました):http://stackoverflow.com/questions/26940378/how-do-i-grab-a-still-image-from-a-cam-using- imwrite-in-opencv-c –