コード例 #1
0
void MultiCamshiftUI::drawResults(int camera, IplImage *image) {
  CvBox2D *box = &results[camera];

  /* Check the roll quality. For aspect ratios near 1, the box rotation
   * can't be measured accurately. In these situations, we draw the box
   * as a circle, to convey this information.
   */
  float q = box->size.height / box->size.width;
  if (q < 1.25) {
    cvCircleAA(image, cvPoint((int)box->center.x, (int)box->center.y),
	       (int)((box->size.height + box->size.width)/4), CV_RGB(0,255,128));
  }
  else {
    draw_box(image, *box);
  }

  /* Always draw some crosshairs at the box center */
  draw_crosshairs(image, box->center.x, box->center.y);
}
コード例 #2
0
static int drawing_test()
{
    static int read_params = 0;
    static int read = 0;
    const int channel = 3;
    CvSize size = cvSize(600, 300);

    int i, j;
    int Errors = 0;

    if( !read_params )
    {
        read_params = 1;

        trsCaseRead( &read, "/n/y", "y", "Read from file ?" );
    }
    // Create image
    IplImage* image = cvCreateImage( size, IPL_DEPTH_8U, channel );

    // cvLine
    cvZero( image );

    for( i = 0; i < 100; i++ )
    {
        CvPoint p1 = cvPoint( i - 30, i * 4 + 10 );
        CvPoint p2 = cvPoint( size.width + 30 - i, size.height - 10 - i * 4 );

        cvLine( image, p1, p2, CV_RGB(178+i, 255-i, i), i % 10 );
    }
    Errors += ProcessImage( image, "cvLine", read );

    // cvLineAA
    cvZero( image );

    for( i = 0; i < 100; i++ )
    {
        CvPoint p1 = cvPoint( i - 30, i * 4 + 10 );
        CvPoint p2 = cvPoint( size.width + 30 - i, size.height - 10 - i * 4 );

        cvLine( image, p1, p2, CV_RGB(178+i, 255-i, i), 1, CV_AA, 0 );
    }
    //Errors += ProcessImage( image, "cvLineAA", read );

    // cvRectangle
    cvZero( image );

    for( i = 0; i < 100; i++ )
    {
        CvPoint p1 = cvPoint( i - 30, i * 4 + 10 );
        CvPoint p2 = cvPoint( size.width + 30 - i, size.height - 10 - i * 4 );

        cvRectangle( image, p1, p2, CV_RGB(178+i, 255-i, i), i % 10 );
    }
    Errors += ProcessImage( image, "cvRectangle", read );

#if 0
        named_window( "Diff", 0 );
#endif

    // cvCircle
    cvZero( image );

    for( i = 0; i < 100; i++ )
    {
        CvPoint p1 = cvPoint( i * 3, i * 2 );
        CvPoint p2 = cvPoint( size.width - i * 3, size.height - i * 2 );

        cvCircle( image, p1, i, CV_RGB(178+i, 255-i, i), i % 10 );
        cvCircle( image, p2, i, CV_RGB(178+i, 255-i, i), i % 10 );

#if 0
        show_iplimage( "Diff", image );
        wait_key(0);
#endif
    }
    Errors += ProcessImage( image, "cvCircle", read );

    // cvCircleAA
    cvZero( image );

    for( i = 0; i < 100; i++ )
    {
        CvPoint p1 = cvPoint( i * 3, i * 2 );
        CvPoint p2 = cvPoint( size.width - i * 3, size.height - i * 2 );

        cvCircleAA( image, p1, i, RGB(i, 255 - i, 178 + i), 0 );
        cvCircleAA( image, p2, i, RGB(i, 255 - i, 178 + i), 0 );
    }
    Errors += ProcessImage( image, "cvCircleAA", read );

    // cvEllipse
    cvZero( image );

    for( i = 10; i < 100; i += 10 )
    {
        CvPoint p1 = cvPoint( i * 6, i * 3 );
        CvSize axes = cvSize( i * 3, i * 2 );

        cvEllipse( image, p1, axes,
                   180 * i / 100, 90 * i / 100, 90 * (i - 100) / 100,
                   CV_RGB(178+i, 255-i, i), i % 10 );
    }
    Errors += ProcessImage( image, "cvEllipse", read );

    // cvEllipseAA
    cvZero( image );

    for( i = 10; i < 100; i += 10 )
    {
        CvPoint p1 = cvPoint( i * 6, i * 3 );
        CvSize axes = cvSize( i * 3, i * 2 );

        cvEllipseAA( image, p1, axes,
                   180 * i / 100, 90 * i / 100, 90 * (i - 100) / 100,
                   RGB(i, 255 - i, 178 + i), i % 10 );
    }
    Errors += ProcessImage( image, "cvEllipseAA", read );

    // cvFillConvexPoly
    cvZero( image );

    for( j = 0; j < 5; j++ )
        for( i = 0; i < 100; i += 10 )
        {
            CvPoint p[4] = {{ j * 100 - 10, i }, { j * 100 + 10, i },
                            { j * 100 + 30, i * 2 }, { j * 100 + 170, i * 3 }};
            cvFillConvexPoly( image, p, 4, CV_RGB(178+i, 255-i, i) );

        }
    Errors += ProcessImage( image, "cvFillConvexPoly", read );

    // cvFillPoly
    cvZero( image );

    for( i = 0; i < 100; i += 10 )
    {
        CvPoint p0[] = {{-10, i}, { 10, i}, { 30, i * 2}, {170, i * 3}};
        CvPoint p1[] = {{ 90, i}, {110, i}, {130, i * 2}, {270, i * 3}};
        CvPoint p2[] = {{190, i}, {210, i}, {230, i * 2}, {370, i * 3}};
        CvPoint p3[] = {{290, i}, {310, i}, {330, i * 2}, {470, i * 3}};
        CvPoint p4[] = {{390, i}, {410, i}, {430, i * 2}, {570, i * 3}};

        CvPoint* p[] = {p0, p1, p2, p3, p4};

        int n[] = {4, 4, 4, 4, 4};
        cvFillPoly( image, p, n, 5, CV_RGB(178+i, 255-i, i) );
    }
    Errors += ProcessImage( image, "cvFillPoly", read );

    // cvPolyLine
    cvZero( image );

    for( i = 0; i < 100; i += 10 )
    {
        CvPoint p0[] = {{-10, i}, { 10, i}, { 30, i * 2}, {170, i * 3}};
        CvPoint p1[] = {{ 90, i}, {110, i}, {130, i * 2}, {270, i * 3}};
        CvPoint p2[] = {{190, i}, {210, i}, {230, i * 2}, {370, i * 3}};
        CvPoint p3[] = {{290, i}, {310, i}, {330, i * 2}, {470, i * 3}};
        CvPoint p4[] = {{390, i}, {410, i}, {430, i * 2}, {570, i * 3}};

        CvPoint* p[] = {p0, p1, p2, p3, p4};

        int n[] = {4, 4, 4, 4, 4};
        cvPolyLine( image, p, n, 5, 1, CV_RGB(178+i, 255-i, i), i % 10 );
    }
    Errors += ProcessImage( image, "cvPolyLine", read );

    // cvPolyLineAA
    cvZero( image );

    for( i = 0; i < 100; i += 10 )
    {
        CvPoint p0[] = {{-10, i}, { 10, i}, { 30, i * 2}, {170, i * 3}};
        CvPoint p1[] = {{ 90, i}, {110, i}, {130, i * 2}, {270, i * 3}};
        CvPoint p2[] = {{190, i}, {210, i}, {230, i * 2}, {370, i * 3}};
        CvPoint p3[] = {{290, i}, {310, i}, {330, i * 2}, {470, i * 3}};
        CvPoint p4[] = {{390, i}, {410, i}, {430, i * 2}, {570, i * 3}};

        CvPoint* p[] = {p0, p1, p2, p3, p4};

        int n[] = {4, 4, 4, 4, 4};
        cvPolyLineAA( image, p, n, 5, 1, RGB(i, 255 - i, 178 + i), 0 );
    }
    Errors += ProcessImage( image, "cvPolyLineAA", read );

    // cvPolyLineAA
    cvZero( image );

    for( i = 1; i < 10; i++ )
    {
        CvFont font;
        cvInitFont( &font, CV_FONT_VECTOR0,
                    (double)i / 5, (double)i / 5, (double)i / 10, i );
        cvPutText( image, "privet. this is test. :)", cvPoint(0, i * 20), &font, CV_RGB(178+i, 255-i, i) );
    }
    Errors += ProcessImage( image, "cvPutText", read );

    cvReleaseImage( &image );

    return Errors ? trsResult( TRS_FAIL, "errors" ) : trsResult( TRS_OK, "ok" );
}