[ADD] auto calibration in startup scene
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/video.hpp>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "ObjectDetection.h"
|
||||
#include "BackgroundRemover.h"
|
||||
@@ -10,6 +11,8 @@
|
||||
#include "async/StaticCameraInstance.h"
|
||||
#include "calibration/HandCalibrator.h"
|
||||
|
||||
#define TIME_DURATION 1.0f
|
||||
|
||||
namespace computervision
|
||||
{
|
||||
|
||||
@@ -25,6 +28,11 @@ namespace computervision
|
||||
handcalibration::HandCalibrator hand_calibrator;
|
||||
|
||||
cv::VideoCapture cap = static_camera::getCap();
|
||||
float time = 0;
|
||||
int seconds_left = 5; // calibration countdown
|
||||
|
||||
bool background_calibrated = false;
|
||||
bool skin_calibrated = false;
|
||||
|
||||
ObjectDetection::ObjectDetection()
|
||||
{
|
||||
@@ -42,6 +50,27 @@ namespace computervision
|
||||
|
||||
bool ObjectDetection::DetectHand(Mat camera_frame, bool& hand_present)
|
||||
{
|
||||
//calculate deltatime
|
||||
|
||||
double current_time = glfwGetTime();
|
||||
static double last_frame_time = current_time;
|
||||
double delt_time = current_time - last_frame_time;
|
||||
std::cout << "delta time : " << delt_time << std::endl;
|
||||
last_frame_time = current_time;
|
||||
|
||||
time += delt_time;
|
||||
|
||||
if (time >= TIME_DURATION)
|
||||
{
|
||||
std::cout << "timer finised, seconds left: " << seconds_left << std::endl;
|
||||
seconds_left--;
|
||||
time = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Mat input_frame = GenerateHandMaskSquare(camera_frame);
|
||||
frame_out = input_frame.clone();
|
||||
|
||||
@@ -62,11 +91,39 @@ namespace computervision
|
||||
|
||||
// draw the hand rectangle on the camera input, and draw text showing if the hand is open or closed.
|
||||
DrawHandMask(&camera_frame);
|
||||
|
||||
|
||||
if (seconds_left <= 0)
|
||||
{
|
||||
if (!background_calibrated)
|
||||
{
|
||||
background_remover.calibrate(input_frame);
|
||||
background_calibrated = true;
|
||||
hand_calibrator.SetBackGroundCalibrated(background_calibrated);
|
||||
seconds_left = 5;
|
||||
time = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (!skin_calibrated)
|
||||
{
|
||||
skin_detector.calibrate(input_frame);
|
||||
skin_calibrated = true;
|
||||
hand_calibrator.SetSkinCalibration(skin_calibrated);
|
||||
time = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
hand_calibrator.SetAmountOfFingers(fingers_amount);
|
||||
finger_count.DrawHandContours(camera_frame);
|
||||
hand_calibrator.DrawHandCalibrationText(camera_frame);
|
||||
std::string calibration_text = (!background_calibrated ? "calibrating background in " : (!skin_calibrated ? "calibrating skin in " : ""));
|
||||
calibration_text += std::to_string(seconds_left);
|
||||
if (!background_calibrated || !skin_calibrated)
|
||||
cv:putText(camera_frame, calibration_text, cv::Point(5, 400), cv::FONT_HERSHEY_COMPLEX, 1.0, cv::Scalar(255, 0, 255),2);
|
||||
|
||||
imshow("camera", camera_frame);
|
||||
|
||||
/*imshow("output", frame_out);
|
||||
@@ -74,7 +131,7 @@ namespace computervision
|
||||
imshow("handMask", handMask);
|
||||
imshow("handDetection", fingerCountDebug);*/
|
||||
|
||||
hand_present = hand_calibrator.CheckIfHandPresent(handMask,handcalibration::HandDetectionType::MENU);
|
||||
hand_present = hand_calibrator.CheckIfHandPresent(handMask, handcalibration::HandDetectionType::MENU);
|
||||
hand_calibrator.SetHandPresent(hand_present);
|
||||
|
||||
|
||||
|
||||
@@ -42,5 +42,7 @@ namespace toolbox
|
||||
* @return: True if the timer has finished
|
||||
*/
|
||||
bool HasFinished() const { return has_finished; }
|
||||
|
||||
void Reset() { current_time = 0; }
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user