【发布时间】:2013-01-27 19:17:38
【问题描述】:
我使用 Qt 制作了一个简单的图形用户界面,并使用 OpenCV 对网络摄像头流进行处理,即精明边缘检测。
我尝试在网络摄像头的两个显示器之间实现切换:
1*) “正常模式”:一种灰度显示,其中网络摄像头提供具有灰度颜色的边界检测视频
2*) "greenMode" :绿色和黑色显示,其中网络摄像头提供相同的“检测到边界”,但具有绿色和黑色。
第一个作品(带有灰度)作品。结果如下:
现在我遇到了第二个问题。这是我找不到解决方案的代码部分:
// Init capture
capture = cvCaptureFromCAM(0);
first_image = cvQueryFrame( capture );
// Init current qimage
current_qimage = QImage(QSize(first_image->width,first_image->height),QImage::Format_RGB32);
IplImage* frame = cvQueryFrame(capture);
int w = frame->width;
int h = frame->height;
if (greenMode) // greenMode : black and green result
{
current_image = cvCreateImage(cvGetSize(frame),8,3);
cvCvtColor(frame,current_image,CV_BGR2RGB);
for(int j = 0; j < h; j++)
{
for(int i = 0; i < w; i++)
{
current_qimage.setPixel(i,j,qRgb(current_image->imageData[i+j*w+1],current_image->imageData[i+j*w+1],current_image->imageData[i+j*w+1]));
}
}
}
else // normal Mode : grayscale result WHICH WORKS
{
current_image = cvCreateImage(cvGetSize(frame),8,1);
cvCvtColor(frame,current_image,CV_BGR2GRAY);
for(int j = 0; j < h; j++)
{
for(int i = 0; i < w; i++)
{
current_qimage.setPixel(i,j,qRgb(current_image->imageData[i+j*w+1],current_image->imageData[i+j*w+1],current_image->imageData[i+j*w+1]));
}
}
}
gaussianfilter(webcam_off);
border_detect(webcam_off);
cvReleaseImage(¤t_image);
repaint();
“greenMode”似乎没有用这个“setPixel”放置好的像素(我取中间的 rgb 值:current_image->imageData[i+j*w+1]):
current_image = cvCreateImage(cvGetSize(frame),8,3);
cvCvtColor(frame,current_image,CV_BGR2RGB);
for(int j = 0; j < h; j++)
{
for(int i = 0; i < w; i++)
{
current_qimage.setPixel(i,j,qRgb(current_image->imageData[i+j*w+1],current_image->imageData[i+j*w+1],current_image->imageData[i+j*w+1]));
}
}
这是我得到的:
首先,输出不是绿色和黑色,其次,与灰度图像相比,它是缩放的。
你有什么线索可以得到greenMode吗?
【问题讨论】: