2 jack yezi jack_yezi 于 2014.11.01 17:19 提问

opencv-c++视频缩放问题

这是部分代码
void CMy3dshowDlg::OnShow(CString File)
{
CvSize dst_Size;
dst_Size.width=0;
dst_Size.height=0;
scale=1.0;

cvNamedWindow("Show",0);
cvResizeWindow("Show",nScreenWidth/2,nScreenHeight/2);
cvMoveWindow("Show",nScreenWidth/4,nScreenHeight/4);
HWND hWnd = (HWND)cvGetWindowHandle("Show"); 
hWnd = ::GetParent(hWnd);
LONG style = GetWindowLong( hWnd, GWL_STYLE);

style = style & (~WS_CAPTION & ~WS_BORDER & ~WS_THICKFRAME); 
SetWindowLong( hWnd, GWL_STYLE, style);
SetClassLong(hWnd,-10,(LONG)GetStockObject(BLACK_BRUSH));
cvSetMouseCallback("Show",my_mouse_callback,this);
g_capture = cvCreateFileCapture(File);

while(1)
{
    frame = cvQueryFrame(g_capture);
    int nFrame = (int)cvGetCaptureProperty(g_capture,CV_CAP_PROP_FRAME_COUNT);
    int currentFrame = (int)cvGetCaptureProperty(g_capture,CV_CAP_PROP_POS_FRAMES);
    if (currentFrame==nFrame-1){
            cvSetCaptureProperty(g_capture,CV_CAP_PROP_POS_FRAMES,0);
        }
    if(!frame==NULL)
    {
        dst_Size.width=frame->width  * scale;
        dst_Size.height=frame->height * scale;
        dstframe=cvCreateImage(dst_Size,frame->depth,frame->nChannels);
        cvResize(frame,dstframe);
        //cvMoveWindow("Show",(nScreenWidth-dst_Size.width)/2,(nScreenHeight-dst_Size.height)/2);
        if(dstframe->width<nScreenWidth||dstframe->height<nScreenHeight){
            cvShowImage("Show",dstframe);
        }
        cvReleaseImage(&dstframe);
    }
    else
    {
        cvShowImage("Show",frame);
    }

    double currentFrameWidth = cvGetCaptureProperty(g_capture,CV_CAP_PROP_FRAME_WIDTH);

    char c = cvWaitKey(33);
    switch (c)
    {
    case ' ':
        while(1)
        {
            c = cvWaitKey(0);
            if(c == ' ') break;
        }break;
    case '+':
        {
            if((frame->width*scale)<=nScreenWidth&&(frame->height*scale)<=nScreenHeight){
                scale=scale+0.1;
                break;
            }
            break;
        }break;
    case'-':
        {
            if((frame->width*scale)>nScreenWidth/7&&(frame->height*scale)>nScreenHeight/7){
                scale=scale-0.1;
                break;
            }break;
        }
        break;
    default:
        break;
    }   
}
cvSetMouseCallback("Show",NULL,NULL);
cvReleaseImage(&frame);
cvReleaseImage(&dstframe);
cvReleaseCapture(&g_capture);
return;

}
本来是想要做视频缩放的,之前是通过缩放窗口来达到效果,可以实现,不过现在不想要这种效果,所以我想固定窗口,然后实现视频的缩放,所以我只在这里做了改变cvNamedWindow("Show",0);
cvResizeWindow("Show",nScreenWidth/2,nScreenHeight/2);
cvMoveWindow("Show",nScreenWidth/4,nScreenHeight/4);,发现不能达到缩放,只是分辨率改变了。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!