Template::Template(std::string name, PointVector points) : Name(name), references(0)
    {
        for (size_t i = 0; i < points.size(); ++i)
        {
            Points.push_back(PointPtr(new Point(points[i]->X,points[i]->Y)));
        }

        Resample(Points, NumPoints);
        RotateToZero(Points);
        ScaleToSquare(Points, SquareSize);
        TranslateToOrigin(Points);
    }
    ResultPtr Recognize(PointVector& points, TemplateVector& templates)
	{
		Resample(points, NumPoints);
		RotateToZero(points);
		ScaleToSquare(points, SquareSize);
		TranslateToOrigin(points);

		double b = DBL_MAX;
		int index = 0;
		for (size_t i = 0; i < templates.size(); ++i)
		{
			double d = DistanceAtBestAngle(points, templates[i], -AngleRange, +AngleRange, AnglePrecision);
			if (d < b)
			{
				b = d;
				index = i;
			}
		}
		double score = 1.0 - (b / HalfDiagonal);
		return ResultPtr(new Result(templates[index]->Name, score));
	};
Exemple #3
0
LRESULT CVideoMarkup::OnPaint( UINT, WPARAM, LPARAM, BOOL& ) {
	PAINTSTRUCT ps;

    HDC hdc = BeginPaint(&ps);
    Rect drawBounds(0,0,VIDEO_X,VIDEO_Y);
    Rect videoBounds(0,0,m_videoLoader.videoX,m_videoLoader.videoY);
    Rect videoBoundsExt(2,2,m_videoLoader.videoX-4,m_videoLoader.videoY-4);

    if (m_videoLoader.videoLoaded) {
        graphics->SetClip(drawBounds);

        if (m_videoLoader.bmpVideo != NULL) {
            if (showGuesses && !scrubbingVideo) { // highlight computer's guesses
                graphics->DrawImage(m_videoLoader.GetMaskedBitmap(),drawBounds);
            } else {
                graphics->DrawImage(m_videoLoader.bmpVideo,drawBounds);
            }
        }

        Rect selectRect;
        selectRect.X = (INT) min(selectStart.X, selectCurrent.X);
        selectRect.Y = (INT) min(selectStart.Y, selectCurrent.Y);
        selectRect.Width = (INT) abs(selectStart.X - selectCurrent.X);
        selectRect.Height = (INT) abs(selectStart.Y - selectCurrent.Y);

        if (selectingRegion) {
            if (currentGroupId == GROUPID_POSSAMPLES) {
                graphics->FillRectangle(&posBrush, selectRect);
                graphics->DrawRectangle(&posSelectPen, selectRect);
            } else {
                graphics->FillRectangle(&negBrush, selectRect);
                graphics->DrawRectangle(&negSelectPen, selectRect);
            }
        }
        graphics->ResetClip();
    }

    graphicsExamples->FillRectangle(&ltgrayBrush, Rect(0,0,EXAMPLEWINDOW_WIDTH,EXAMPLEWINDOW_HEIGHT));
    if (classifier->isTrained) {
        graphicsExamples->DrawImage(classifier->GetFilterImage(),10,0);
	    graphicsExamples->DrawString(L"RECOGNIZER MODEL", 16, &labelFont, PointF(15,5), &whiteBrush);
	}
    if (showGuesses) {
        graphicsExamples->DrawImage(classifier->GetApplyImage(),FILTERIMAGE_WIDTH+20, 0);
	    graphicsExamples->DrawString(L"RECOGNIZER OUTPUT", 17, &labelFont, PointF(FILTERIMAGE_WIDTH+25,5), &whiteBrush);
    }
	if (classifier->isOnDisk) {
		LPWSTR name = classifier->GetName();
		graphicsExamples->DrawString(L"Currently\nActive:", 17, &labelFont, PointF(2*FILTERIMAGE_WIDTH+30,10), &blackBrush);
	    graphicsExamples->DrawString(name, wcslen(name), &bigFont,
			RectF(2*FILTERIMAGE_WIDTH+30,50,EXAMPLEWINDOW_WIDTH-(2*FILTERIMAGE_WIDTH+30),EXAMPLEWINDOW_HEIGHT-50),
			&stringFormat, &blackBrush);
	}

    if (recognizerMode == GESTURE_FILTER) {
        // draw the current gesture motion trajectory in this frame
        MotionTrack mt = m_videoLoader.GetTrajectoryAtCurrentFrame();
		mt = ScaleToSquare(mt, 3*VIDEO_Y/4);
		mt = TranslateToOrigin(mt);
		DrawTrack(graphics, mt, VIDEO_X, VIDEO_Y, VIDEO_X);
    }

    BitBlt(hdc,0,0,VIDEO_X,VIDEO_Y,hdcmem,0,0,SRCCOPY);
    BitBlt(hdc,EXAMPLEWINDOW_X,EXAMPLEWINDOW_Y,EXAMPLEWINDOW_WIDTH,EXAMPLEWINDOW_HEIGHT,hdcmemExamples,0,0,SRCCOPY);
    EndPaint(&ps);

    return 0;
}