OpenCV表单应用程序 - 将Mat转换为灰度
OpenCV form application- convert Mat to Grayscale
我有问题,理论上很容易,但是...只是理论上:)我想将垫帧图像转换为灰度。我知道我应该使用这样的东西:
cv::cvtColor(frameA1, grayImageA1, CV_BGR2GRAY);
但结果是这样的:
http://i57.tinypic.com/jfvodt.jpg
我不知道为什么转换为灰度后我有 3 张图像。这是我代码的一部分:
private: System::Void backgroundWorker1_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e) {
BackgroundWorker^ worker = dynamic_cast<BackgroundWorker^>(sender);
capture1.open(1);
while (camStatus1){
if (camBusy1) continue;
capture1.read(frameA1);
if (frameA1.empty()) continue;
cv::cvtColor(frameA1, grayImageA1, CV_BGR2GRAY);
worker->ReportProgress(1);
}
}
private: System::Void backgroundWorker1_ProgressChanged(System::Object^ sender, System::ComponentModel::ProgressChangedEventArgs^ e) {
if (!camBusy1){
camBusy1 = 1;
System::Drawing::Graphics^ graphics = imageBox1->CreateGraphics();
System::IntPtr ptr(frameA1.ptr());
System::Drawing::Bitmap^ b = gcnew System::Drawing::Bitmap(frameA1.cols, frameA1.rows, frameA1.step, System::Drawing::Imaging::PixelFormat::Format24bppRgb, ptr);
System::Drawing::RectangleF rect(0, 0, imageBox1->Width, imageBox1->Height);
graphics->DrawImage(b, rect);
if (debugA){
System::Drawing::Graphics^ graphics = imageBox3->CreateGraphics();
System::IntPtr ptr(grayImageA1.ptr());
System::Drawing::Bitmap^ b = gcnew System::Drawing::Bitmap(grayImageA1.cols, grayImageA1.rows, grayImageA1.step, System::Drawing::Imaging::PixelFormat::Format24bppRgb, ptr);
System::Drawing::RectangleF rect(0, 0, imageBox3->Width, imageBox3->Height);
graphics->DrawImage(b, rect);
}
camBusy1 = 0;
}
}
知道为什么它会这样工作吗?我希望你能帮助我解决这个理论上简单的问题:)
我敢打赌,你的cvtColor()调用工作正常(尝试imwrite()输出,然后看看你自己),但是:
您正在尝试使用 24 位像素标志对 8 位图像进行 bling 处理:
System::Drawing::Bitmap^ b = gcnew System::Drawing::Bitmap(grayImageA1.cols, grayImageA1.rows, grayImageA1.step, System::Drawing::Imaging::PixelFormat::Format24bppRgb, ptr);
如果要保留像素标志,则必须再次转换为3通道:
Mat grayImage24;
cv::cvtColor(grayImageA1, grayImage24, CV_GRAY2BGR);
System::Drawing::Bitmap^ b = gcnew System::Drawing::Bitmap(grayImage24.cols, grayImage24.rows, grayImage24.step, System::Drawing::Imaging::PixelFormat::Format24bppRgb, ptr);
(现在不能尝试,但是IIRC,没有办法用Winforms对8位图像进行bled)
相关文章:
- OpenCV - 如何将灰度转换为彩色(CV_8UC3)?
- C++ Gdi+将图像转换为灰度
- 将 BMP 图像转换为灰度
- 颜色到灰度转换
- 如何将图像转换为灰度 opengl c++
- 如何正确将位图转换为 OpenCV 灰度垫
- 将 YUV420p QVideoFrame 转换为灰度 OpenCV 垫
- Qmage:使用颜色表从灰度转换为RGB
- 在OpenCV中将灰度图像转换为单色
- Mat的convertTo函数在OpenCV中将灰度图像的类型转换为CV_32F时抱怨断言错误
- 使用某些系数将图像转换为灰度的最快方法
- OPENCV:从RGB转换为灰度只有蓝色
- 在C++中将彩色位图转换为灰度
- 如何将灰度/二进制垫子转换为qimage
- 使用libpng将转换设置为灰度
- 使用煤渣转换为灰度
- 将颜色图像转换为OpenCV中的灰度问题
- 在open cv中,我如何将灰度图像转换回RGB图像(颜色)
- Opencv L*a*b*到RGB的转换产生灰度输出
- 从灰度图像到QImage的快速转换