Qtを使用してシンプルなグラフィカルユーザーインターフェイスを作成し、OpenCVを使用してWebカメラストリーミングの処理、つまりキャニーエッジ検出を行いました。
ウェブカメラの2つのディスプレイ間の切り替えを実装しようとしています:
1 *)「通常モード」:ウェブカメラがグレースケールカラーの境界検出ビデオを提供するグレースケールディスプレイ
2 *)「greenMode」:ウェブカメラが同じ「境界線を検出」しますが、緑と黒の色で表示される緑と黒のディスプレイ。
最初のものは(グレースケールで)動作します。結果は次のとおりです。
今、私は2番目のものに問題があります。これが私が解決策を見つけることができないコードの部分です:
// 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を取得するための手がかりはありますか?