0805Jason 2014-11-01 09:19 采纳率: 0%
浏览 1661

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);,发现不能达到缩放,只是分辨率改变了。

  • 写回答

1条回答

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-20 17:57
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置