参照大侠的文章,自己经过测试与简化,形成如下内容。
参考文章地址https://blog.csdn.net/qq_40094716/article/details/120501356
经过测试,下述代码有效,能够确保视频处于无边框状态
//全局变量
BOOL bCaptured = 0;
BOOL bExit = 0;
cv::VideoCapture cap;
Mat frame;
// ----------- 操作函数
void CameraPrepare()
{
bExit = 0;
}
void CloseCamera()
{
bExit = 1;
}
void CaptureGraph()
{
bCaptured = 1;
}
//----------- 主要函数
int openTheCamera(HWND hWnd,int idx)//开启摄像头,hwnd父窗口句柄,idx摄像头索引号
{
int kk=0;
cap.open(idx);
if (!cap.isOpened())
{
TRACE1("Error: openCamera() failed to open camera %d\n",idx);
return -1;
}
cv::namedWindow("tod",0);
HWND hd = FindWindowW(0,L"tod");
::SetWindowPos(hd,HWND_TOPMOST,700,200,600,500,SWP_NOZORDER);
::SetWindowLong(hd,GWL_STYLE,GetWindowLong(hd, GWL_EXSTYLE)|WS_EX_TOPMOST);
::SetWindowPos(hd,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
ShowWindow(hd,SW_SHOW);
while (true)
{
cap.read(frame);
cv::imshow("tod", frame);
if(bExit || (waitKey(5) >= 0))//监听键盘,按任意键退出,或按钮退出
{
cv::destroyWindow("tod");
break;
}
if(bCaptured)//抓取视频存图,并发送通知
{
if(imwrite("001.png",frame))
::PostMessageW(hWnd,5000,0,0);
bCaptured = 0;
}
}
cap.release();
return 0;
}
如下图所示,视频窗口当中的标题栏之类的已经去掉了,也没有边框了。