openCVとC++を使用して歩行のモーション認識を行っていますが、提供された画像に見られる効果を実現するために、マスクまたはコピーされた画像を作成したいと思います。以下は画像の説明です。結果として生じる人間の歩行の塊が見られます。次に、元のフレームのマスク画像またはコピーされた画像が作成され、バイナリの人間のブロブがマスクされ、マスクされていないピクセルがゼロに設定されます。結果は、黒い背景で抽出された人体です。次の図は、人間のブロブが抽出されてからマスクされる方法を示しています。これは、ビデオシーケンスの5番目のフレームごとに実行されます。これまでの私のコードは、5フレームごとに取得し、グレースケーリングし、すべてのブロブの領域を見つけ、しきい値を適用して、人間のブロブだけが白で残りの画像が白であるバイナリ画像を取得することで構成されています。黒。今、人体を抜こうとしていますが、どうすればいいのかわかりません。私を助けてください。
#include "cv.h"
#include "highgui.h"
#include "iostream"
using namespace std;
int main( int argc, char* argv ) {
CvCapture *capture = NULL;
capture = cvCaptureFromAVI("C:\\walking\\lady walking.avi");
if(!capture){
return -1;
}
IplImage* color_frame = NULL;
IplImage* gray_frame = NULL ;
int thresh_frame = 28;
CvMoments moments;
int frameCount=0;//Counts every 5 frames
cvNamedWindow( "walking", CV_WINDOW_AUTOSIZE );
while(1) {
color_frame = cvQueryFrame( capture );//Grabs the frame from a file
if( !color_frame ) break;
gray_frame = cvCreateImage(cvSize(color_frame->width, color_frame->height), color_frame->depth, 1);
if( !color_frame ) break;// If the frame does not exist, quit the loop
frameCount++;
if(frameCount==5)
{
cvCvtColor(color_frame, gray_frame, CV_BGR2GRAY);
cvThreshold(gray_frame, gray_frame, thresh_frame, 255, CV_THRESH_BINARY);
cvErode(gray_frame, gray_frame, NULL, 1);
cvDilate(gray_frame, gray_frame, NULL, 1);
cvMoments(gray_frame, &moments, 1);
double m00;
m00 = cvGetCentralMoment(&moments, 0,0);
cvShowImage("walking", gray_frame);
frameCount=0;
}
char c = cvWaitKey(33);
if( c == 27 ) break;
}
double m00 = (double)cvGetCentralMoment(&moments, 0,0);
cout << "Area - : " << m00 << endl;
//area of lady walking = 39696. Therefore, using new threshold area as 30 for this video
//area of walking man = 67929
cvReleaseImage(&color_frame);
cvReleaseImage(&gray_frame);
cvReleaseCapture( &capture );
cvDestroyWindow( "walking" );
return 0;
}
また、コードで使用しているビデオをアップロードしたいのですが、ここでアップロードする方法がわからないので、誰かがそれを手伝ってくれるなら。質問に対してできるだけ多くの情報を提供したいと思います。