0

特定のコーディングを理解するのに問題があります。これがばかげている場合は申し訳ありませんが、ウェブカメラからビデオをキャプチャするコードを持っています。フレームから RGB 値を取得したいのですが、これが不可能な場合は、ファイルを保存する必要があります。画像としてフレームを作成し、そこから値を取得しますか?

const char window_name[]="ウェブカメラ";

int main(int argc, char* argv[]) {

/* attempt to capture from any connected device */
CvCapture *capture=cvCaptureFromCAM(CV_CAP_ANY);
if(!capture)
{
    printf("Failed to initialise webcam\n");
    return -1;
}

/* create the output window */
cvNamedWindow(window_name, CV_WINDOW_NORMAL);

do
{
    /* attempt to grab a frame */

    IplImage *frame=cvQueryFrame(capture);
    if(!frame)
    {
        printf("Failed to get frame\n");
        break;
    }


    COLORREF myColAbsolute = GetPixel(frame, 10,10);//error in saying frame is not compatible with HDC.

    cout << "Red - " << (int)GetRValue(myColAbsolute) << endl;
    cout << "Green - " << (int)GetGValue(myColAbsolute) << endl;
    cout << "Blue - " << (int)GetBValue(myColAbsolute) << endl;


    /* show the frame */
    cvShowImage(window_name, frame);
4

1 に答える 1

1

ハ!(明らかにコピー&ペーストバマーで捕まえられました)

GetPixel()はWindows関数であり、opencv関数ではありません。GetRValue()と姉妹についても同じです。

ネイティブのwin32apiでそれらを使用して、HDCからピクセルを取得しますが、HDCもHWNDも公開されていないため、opencv/highguiでは機能しません。

あなたは明らかに初心者なので(これも問題ありません!)、古い1.0 opencv api(IplImages、cv * Functions)も使用しないように話させてください。新しいもの(cv)を使用する必要があります。 :: Mat、名前空間cv :: Functions)代わりに。

#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"

using namespace cv;
using namespace std;

int main()
{
    Mat frame;
    namedWindow("video", 1);

    VideoCapture cap(0);
    while ( cap.isOpened() )
    {
        cap >> frame;
        if(frame.empty()) break;

                int x=3, y=5;
                // Ladies and Gentlemen, the PIXEL!
                Vec3b pixel = frame.at<Vec3b>(y,x); // row,col, not x,y!
                cerr << "b:" << int(pixel[0]) << " g:" << int(pixel[1]) << " r:" << int(pixel[2]) << endl;

        imshow("video", frame);
        if(waitKey(30) >= 0) break;
    }   
    return 0;
}
于 2013-03-13T19:32:21.350 に答える