我是一名学习计算机视觉的学生,我正在研究我的项目,但我遇到了问题。首先,我的项目是将视频投射到人的衣服上(就像图像映射一样)。我们通过红外摄像机认出这个人,背景是白色的(除了白墙之外什么都没有)。在软件中,图像被转换为黑白图像,因此人为白色,背景为黑色。
以下是我的项目的视频和源代码:
while(1)
{
//grabbing infrared camera
ppCameras[0]->RetrieveBuffer(&cam1_img);
cam1_img.Convert(PIXEL_FORMAT_BGR, &cam1_RGBconverted_img);
memcpy(p_image->data,cam1_RGBconverted_img.GetData(),cam1_RGBconverted_img.GetDataSize());
//time check
time1 = time2;
time2 = timeGetTime();
cout << "PART 1:" << time2 - time1 <<"ms"<<endl;
//image setting
contents_originMOV >> contents_originMOV_frame;
if(firstPlay==0)
{
firstPlay=1;
width = (int)contents_originMOV.get(CV_CAP_PROP_FRAME_WIDTH);
height = (int)contents_originMOV.get(CV_CAP_PROP_FRAME_HEIGHT);
fps = (int)contents_originMOV.get(CV_CAP_PROP_FPS);
count = (int)contents_originMOV.get(CV_CAP_PROP_FRAME_COUNT);
}
nowFrame = (int)contents_originMOV.get(CV_CAP_PROP_POS_FRAMES);
// setting for image repetition
if(nowFrame >= count)
{
contents_originMOV.set(CV_CAP_PROP_POS_FRAMES,0);
if(loopMode==1)
{
loopFirst=1;
}
}
else
{
loopFirst=0;
}
//time check
time1 = time2;
time2 = timeGetTime();
cout << "PART 2.1:" << time2 - time1 <<"ms"<<endl;
key = cvWaitKey(1);
if(key=='q') break;
//time check
time1 = time2;
time2 = timeGetTime();
cout << "PART 2.2:" << time2 - time1 <<"ms"<<endl;
//GPU time check start
StopWatchInterface *timer = NULL;
sdkCreateTimer(&timer);
sdkStartTimer(&timer);
g_image.upload(image3);
g_frame.upload(contents_originMOV_frame);
gpu::cvtColor(g_image,g_grayMask,CV_BGR2GRAY);
gpu::threshold(g_grayMask,g_grayMask, 50, 255, CV_THRESH_BINARY_INV );
gpu::bitwise_not(g_grayMask, g_grayMask);
gpu::morphologyEx(g_grayMask,g_grayMask,MORPH_OPEN,element,buf1,buf2);
gpu::morphologyEx(g_grayMask,g_grayMask,MORPH_CLOSE,element,buf1,buf2);
gpu::cvtColor(g_grayMask,g_grayMask2,CV_GRAY2BGR);
gpu::multiply(g_grayMask2,g_frame,g_grayMask2,1.0/255.0,-1);
g_grayMask2.download(grayMask4);
imshow("compose_right",grayMask4);
//GPU time check end
sdkStopTimer(&timer);
float time = sdkGetTimerValue(&timer);
cout << "GPUTime:" << time <<"ms"<<endl;
}
我构建了这个代码,速度是20~30ms(我认为这足以跟随人的运动,但速度很慢)。我不知道为什么投影机不能跟随人的运动速度。我使用visual studio 2010 64bit,opencv2.4.6和cuda 5.5版本。
这是我的问题:
有没有办法加快投影机的性能速度?
可以在CUDA中解决这个问题吗?