C ++を使用してOpenCVで経過時間を計算する方法は?
ここでは、OpenCVを使用して経過時間を計算する方法を理解します。
次のプログラムは、C++を使用してOpenCVの経過時間を計算します。
例
#include<opencv2/opencv.hpp>//OpenCV header to use VideoCapture class//
#include<iostream>
using namespace std;
using namespace cv;
int main() {
Mat myImage;//Declaring a matrix to load the frames//
namedWindow("Video Player");//Declaring the video to show the video//
VideoCapture cap("video.mp4");//Declaring an object to load video from device//
if (!cap.isOpened()){ //This section prompt an error message if no video stream is found//
cout << "No video stream detected" << endl;
system("pause");
return-1;
}
while (true){ //Taking an everlasting loop to show the video//
cap >> myImage;
int elapsed_time;//Declaring an integer variable to store the elapsed time//
elapsed_time=cap.get(CAP_PROP_POS_MSEC);//Reading the elapsed time//
cout << "Ellapsed time(in second):" << elapsed_time / 1000 << endl;//Showing the elapsed time in seconds//
if (myImage.empty()){ //Breaking the loop if no video frame is detected//
break;
}
imshow("Video Player", myImage);//Showing the video//
char c = (char)waitKey(25);//Allowing 25 milliseconds frame processing time and initiating break condition//
if (c == 27){ //If 'Esc' is entered break the loop//
break;
}
}
cap.release();//Releasing the buffer memory//
return 0;
} このプログラムはビデオを再生し、コンソールウィンドウに経過時間を表示します。
出力
-
C ++を使用してOpenCVでバイナリイメージを作成するにはどうすればよいですか?
バイナリイメージは、白黒の2色を表す単なるデジタルイメージです。画像処理の観点から、バイナリ画像には、0と1の2つの可能な値を持つピクセルが含まれています。ピクセルの値が0の場合、それは純粋な黒色を表します。ピクセルの値が1の場合、それは純粋な白色を意味します。 グレースケール画像では、それぞれに256の異なる可能な値があります。しかし、バイナリイメージでは、可能な値は2つだけです。バイナリイメージには、さまざまなタイプのアプリケーションがあります。たとえば、形態学的変換には2値画像が必要であり、背景からのオブジェクト形状の抽出には2値画像が必要です。OpenCVを使用すると、画像を2値画像
-
C ++を使用してOpenCVの画像のチャンネル数を計算するにはどうすればよいですか?
このトピックでは、画像のチャンネル数を確認する方法を理解します。プログラムを実行すると、チャンネル番号がコンソールウィンドウに表示されます。 チャネルの番号を取得するために、channels()という名前のOpenCVのクラスを使用しました。 クラスchannels()のオブジェクトとして画像マトリックスを渡すと、チャネルに整数値が与えられます。 次のプログラムは、チャネルの数をカウントし、コンソールウィンドウに表示します。 例 #include<iostream> #include<opencv2/highgui/highgui.hpp> using namesp