-2

Cに変換する必要のあるC++openCVコードがあります。しかし、代わりに何を使用すべきかを確認するためのガイドが見つかりませんでした。

cvScalar、cvNamedWindow、cvSmooth

また、私のコードに他の問題が見つかった場合は、教えてください。

#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
#include <stdio.h>


IplImage* Threshold(IplImage* src)
{

    IplImage* srcHSV = cvCreateImage(cvGetSize(src), 8, 3);
    cvCvtColor(src, srcHSV, CV_BGR2HSV);// Convert the BGR to HSV

    IplImage* Thresholdimg = cvCreateImage(cvGetSize(src), 8, 1); // create a Threshold image

    // HSV tresholding
cvInRangeS(srcHSV, CvScalar(7, 107, 219), CvScalar(11,148,255), Thresholdimg);

    cvSmooth( Thresholdimg, Thresholdimg, CV_GAUSSIAN, 9, 9 ); // Smoothing with a Gaussian filter (9*9 kernel)


    cvReleaseImage(&srcHSV);

    return Thresholdimg;
}



int main()
{

    CvCapture* capture = 0;
    capture = cvCaptureFromCAM(1);// 1 for usb webcam, 0 o/w.

    if(!capture)
    {
        printf("Can not capture,no device found\n");
        return -1;
    }

    // Windows for Threshold and Output
    cvNamedWindow("Tracking output");
    cvNamedWindow("Threshold");

    while(1) // infinite loop
    {

        IplImage* frame = 0;
        frame = cvQueryFrame(capture); // decompress the captured frame

        if(!frame)
            break;

        IplImage* finalthreshold = Threshold(frame);

        cvShowImage("Threshold", finalthreshold);//show the thresholded image

        CvMemStorage*  storage  = cvCreateMemStorage(0);// allocate memory to store the contour information

        CvSeq* circles = cvHoughCircles(finalthreshold, storage, CV_HOUGH_GRADIENT, 2, finalthreshold->height/4, 100, 40, 20, 200);



        int i;
        for (i = 0; i < circles->total; i++)
        {

            float *p = (float*)cvGetSeqElem(circles, i);
            printf("Ball! x=%f y=%f r=%f\n\r",p[0],p[1],p[2] );
            CvPoint center = cvPoint(cvRound(p[0]),cvRound(p[1]));
            CvScalar val = cvGet2D(finalthreshold, center.y, center.x);

            if (val.val[0] < 1) continue;
            cvCircle(frame,  center, 3,             CV_RGB(0,255,0), -1, CV_AA, 0);
            cvCircle(frame,  center, cvRound(p[2]), CV_RGB(255,0,0),  3, CV_AA, 0);
            cvCircle(finalthreshold, center, 3,             CV_RGB(0,255,0), -1, CV_AA, 0);
            cvCircle(finalthreshold, center, cvRound(p[2]), CV_RGB(255,0,0),  3, CV_AA, 0);
        }



         cvShowImage("Tracking output", frame);


         int c = cvWaitKey(27);
         if(c!=-1)
             break;


         cvReleaseImage(&finalthreshold);

    }


    cvReleaseCapture(&capture);
    return 0;
}

エラーは次のとおりです。

root@ghostrider:/home/zero/Desktop/deneme opencv# opencv untitled.c 
compiling untitled.c
untitled.c: In function ‘Threshold’:
untitled.c:17:2: error: too few arguments to function ‘cvScalar’
In file included from /usr/local/include/opencv2/core/core_c.h:47:0,
                 from /usr/local/include/opencv/cv.h:63,
                 from untitled.c:1:
/usr/local/include/opencv2/core/types_c.h:1224:22: note: declared here
untitled.c:17:2: error: too few arguments to function ‘cvScalar’
In file included from /usr/local/include/opencv2/core/core_c.h:47:0,
                 from /usr/local/include/opencv/cv.h:63,
                 from untitled.c:1:
/usr/local/include/opencv2/core/types_c.h:1224:22: note: declared here
untitled.c:19:2: error: too few arguments to function ‘cvSmooth’
In file included from /usr/local/include/opencv/cv.h:65:0,
                 from untitled.c:1:
/usr/local/include/opencv2/imgproc/imgproc_c.h:81:13: note: declared here
untitled.c: In function ‘main’:
untitled.c:42:2: error: too few arguments to function ‘cvNamedWindow’
In file included from /usr/local/include/opencv/highgui.h:47:0,
                 from untitled.c:2:
/usr/local/include/opencv2/highgui/highgui_c.h:120:12: note: declared here
untitled.c:43:2: error: too few arguments to function ‘cvNamedWindow’
In file included from /usr/local/include/opencv/highgui.h:47:0,
                 from untitled.c:2:
/usr/local/include/opencv2/highgui/highgui_c.h:120:12: note: declared here
Output file => untitled

1224行目/usr/local/include/opencv2/core/types_c.h

CV_INLINE  CvScalar  cvScalar( double val0, double val1 CV_DEFAULT(0),
                               double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0))
4

1 に答える 1

2

あなたが言及する構成は、あなたが与えた名前でCに存在します。C ++APIの代わりにCAPIを使用して、引き続きそれらを使用できます。

cvScalar

cvNamedWindow

cvSmooth

編集: Cの実装にはデフォルトの引数がないことに注意してください。デフォルトの引数をに貼り付けているだけの場合でも、各関数にすべての引数を指定する必要があります。

詳細については、この質問を参照してください。

于 2013-03-26T20:55:45.657 に答える