Ask Your Question
0

cv::mat in mfc

asked 2013-05-11 06:48:21 -0600

am gravatar image

how can u display cv::mat in mfc? i tried finding the answer in google but was unsucessful i'll apperciate any help also is there a opencv gui making prog other than qt and mfc

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2013-05-12 07:11:02 -0600

wuling gravatar image

updated 2019-06-10 19:51:03 -0600

try list:

int ShowMat( cv::Mat img, HWND hWndDisplay )
    {
        if (img.channels()<3 )
        {
            return -1;
        }

        RECT rect;
        GetClientRect(hWndDisplay, &rect);
        cv::Mat imgShow( abs(rect.top - rect.bottom), abs(rect.right - rect.left), CV_8UC3 );
        resize( img, imgShow, imgShow.size() );

        ATL::CImage CI;
        int w=imgShow.cols;//宽
        int h=imgShow.rows;//高
        int channels=imgShow.channels();//通道数

        CI.Create( w, h, 8*channels);
        uchar *pS;
        uchar *pImg=(uchar *)CI.GetBits();//得到CImage数据区地址
        int step=CI.GetPitch();
        for(int i=0;i<h;i++)
        {
            pS=imgShow.ptr<uchar>(i);
            for(int j=0;j<w;j++)
            {
                for(int k=0;k<3;k++)
                    *(pImg+i*step+j*3+k)=pS[j*3+k];
                //注意到这里的step不用乘以3
            }
        }

        HDC dc ;
        dc = GetDC( hWndDisplay );
        CI.Draw( dc, 0, 0 );
        ReleaseDC( hWndDisplay, dc);
        CI.Destroy();

        return 0;
    }
edit flag offensive delete link more

Comments

1

the link is died

jsxyhelu gravatar imagejsxyhelu ( 2019-06-05 18:39:26 -0600 )edit

Question Tools

Stats

Asked: 2013-05-11 06:48:21 -0600

Seen: 2,038 times

Last updated: Jun 10 '19