Threshold(backProjection, backProjectionThresholded, m_backProjectionThreshold, 255, 0) Įrode(backProjectionThresholded, backProjectionThresholded, getStructuringElement(MORPH_RECT, Size(2 * m_erosionSize + 1, 2 * m_erosionSize + 1), Point(m_erosionSize, m_erosionSize))) ĭilate(backProjectionThresholded, backProjectionThresholded, getStructuringElement(MORPH_RECT, Size(2 * m_dilationSize + 1, 2 * m_dilationSize + 1), Point(m_dilationSize, m_dilationSize))) =HISTOGRAM BACK PROJECTIONĬvtColor(frameRoi, frameHSV, CV_BGR2HSV) ĬalcBackProject(&frameHSV, 1, m_calibrationData->m_channels, m_calibrationData->m_hist, backProjection, (const float**)(m_calibrationData->m_ranges), 1, true)
MatchTemplate(frameRoi, m_calibrationData->m_fingerPatch, scoreMap, 3) Using OpenCV matchTemplate function with correlation coefficient matching method Ĝompare current frame roi region to known candidate ScoreMap.create(result_cols, result_rows, CV_32FC1) Int result_rows = frameRoi.rows - m_calibrationData->m_fingerPatch.rows + 1 Īssert(result_cols > 0 & result_rows > 0) Int result_cols = ls - m_calibrationData->m_ls + 1 Std::min(m_currentCandidate.m_windowRect.tl().y + m_roiSpanY + m_calibrationData->m_fingerPatch.rows, frame.rows))) Point(std::min(m_currentCandidate.m_windowRect.tl().x + m_roiSpanX + m_calibrationData->m_ls, ls), Point(std::max(m_currentCandidate.m_windowRect.tl().x - m_roiSpanX, 0), std::max(m_currentCandidate.m_windowRect.tl().y - m_roiSpanY, 0)), Rectangle(frame, fingerWindow.tl(), fingerWindow.br(), Scalar(0, 0, 255)) PutText(frame, "Adjust calibration window, click when ready", Point(0, getTextSize("Adjust calibration window", 0, 0.4, 2, &baseline).height), 0, 0.4, Scalar::all(255), 1) Rectangle(frame, r3.tl() + fingerWindow.tl(), r3.br() + fingerWindow.tl(), c3) Rectangle(frame, r2.tl() + fingerWindow.tl(), r2.br() + fingerWindow.tl(), c2) Rectangle(frame, r1.tl() + fingerWindow.tl(), r1.br() + fingerWindow.tl(), c1) M_currentCandidate.m_fingerPosition = fingerWindow.tl() M_currentCandidate.m_windowRect = fingerWindow M_calibrationData->m_fingerRect = fingerWindow Point( (h+1)*scale - 1, (s+1)*scale - 1),įrame(fingerWindow).copyTo(m_calibrationData->m_fingerPatch) Rectangle( histImg, Point(h*scale, s*scale), Int intensity = cvRound(binVal*255/maxVal) Mat histImg = Mat::zeros(m_calibrationData->m_sbins*scale, m_calibrationData->m_hbins*10, CV_8UC3) įloat binVal = m_calibrationData->m_hist.at(h, s) MinMaxLoc(m_calibrationData->m_hist, 0, &maxVal, 0, 0) Normalize(m_calibrationData->m_hist, m_calibrationData->m_hist, 0, 255, NORM_MINMAX, -1, Mat()) PutText(frame, "Move finger away from camera", Point(0, getTextSize("Move finger away from camera", 0, 0.5, 1, nullptr).height), 0, 0.5, Scalar::all(255), 1) Įlse if (percentageTop m_channels, thd, hist, 2, m_calibrationData->m_histSize, (const float**)m_calibrationData->m_ranges, true, false) Ss = m_calibrationTopUpperThd & percentageBottom >= m_calibrationBottomUpperThd & percentageMiddle >= m_calibrationMiddleUppperThd)
If (percentageTop > m_calibrationTopLowerThd & percentageTop m_calibrationMiddleLowerThd & percentageMiddle m_calibrationBottomLowerThd & percentageBottom std::chrono::seconds(1)) Rect r3 = Rect(0, thd.rows * 2 / 3 + 1, thd.cols, thd.rows - thd.rows * 2 / 3 - 1) Īuto percentageTop = countNonZero(top) * 100.0 / top.size().area() Īuto percentageMiddle = countNonZero(middle) * 100.0 / middle.size().area() Īuto percentageBottom = countNonZero(bottom) * 100.0 / bottom.size().area() Rect r2 = Rect(0, thd.rows / 3 + 1, thd.cols, thd.rows/3) Rect r1 = Rect(0, 0, thd.cols, thd.rows/3) Threshold(ch, ch, m_calibrationDiffThreshold, 255, 0) If (fingerWindowBackgroundGray.rows & !m_calibrationData->m_ready)Ībsdiff(frame(fingerWindow), fingerWindowBackground, diff) If (Xpos + windowSize >= ls || Ypos + windowSize*3 >= frame.rows)įrame(fingerWindow).copyTo(fingerWindowBackground) ĬvtColor(fingerWindowBackground, fingerWindowBackgroundGray, CV_BGR2GRAY) Rect fingerWindow(Point(Xpos, Ypos), Size(windowSize, windowSize*3)) PyrDown(frame, frame, Size(ls / 2, frame.rows / 2)) Std::chrono::system_clock::time_point start = std::chrono::system_clock::now()
M_calibrationData.reset(new CalibrationData()) Mat fingerWindowBackground, fingerWindowBackgroundGray SetMouseCallback("RGB", MouseCallback, (void*)&buttonClicked) Throw std::runtime_error("Could not start camera capture") ĬreateTrackbar("X", "RGB", &Xpos, 320, TrackBarCallback, (void*)&update) ĬreateTrackbar("Y", "RGB", &Ypos, 240, TrackBarCallback, (void*)&update) ĬreateTrackbar("Size", "RGB", &windowSize, 100, TrackBarCallback, (void*)&update)