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 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用