我正在使用opencv将网络摄像头输出到屏幕。
我正常输出屏幕。
然而,有一个问题。
结果中会产生噪音。
我不知道原因。
告诉我该怎么做
以下是初始化函数。
调用imshow函数进行测试。
void CRtspMgr::Init() {
// init video capture
if (m_capture == NULL) {
m_capture = new VideoCapture();
}
// set address
m_capture->open(0);
namedWindow("video", 1);
}
它是绘制屏幕的部分。
void CRtspMgr::OnPaint()
{
// draw video mat
CPaintDC dc(this);
if (m_capture != NULL) {
if (m_capture->isOpened()) {
RECT r;
GetClientRect(&r);
cv::Size winSize(r.right, r.bottom);
Mat mat;
m_capture->read(mat);
// test
imshow("video", mat);
int bpp = 8 * mat.elemSize();
assert((bpp == 8 || bpp == 24 || bpp == 32));
BITMAPINFO bitInfo;
bitInfo.bmiHeader.biBitCount = bpp;
bitInfo.bmiHeader.biWidth = mat.cols;
bitInfo.bmiHeader.biHeight = mat.rows;
bitInfo.bmiHeader.biPlanes = 1;
bitInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitInfo.bmiHeader.biCompression = BI_RGB;
bitInfo.bmiHeader.biClrImportant = 0;
bitInfo.bmiHeader.biClrUsed = 0;
bitInfo.bmiHeader.biSizeImage = 0;
bitInfo.bmiHeader.biXPelsPerMeter = 0;
bitInfo.bmiHeader.biYPelsPerMeter = 0;
int destx = 0, desty = 0;
int destw = winSize.width;
int desth = winSize.height;
int imgx = 0, imgy = 0;
int imgWidth = mat.cols;
int imgHeight = mat.rows;
StretchDIBits(dc,
destx, desty, destw, desth,
imgx, imgy, imgWidth, imgHeight,
mat.data, &bitInfo, DIB_RGB_COLORS, SRCCOPY);
}
}
Invalidate();
}