<commit_before>#include <stdio.h>

#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>
#include <time.h>
#include <unistd.h>
#include <memory>

#include "objectTracking/ColorTracker.h"
#include "objectTracking/Flooder.h"
#include "CoordinateConverter.h"
#include "Pool.h"

enum PROGRAM_STATE
{
    WAIT_FOR_SELECT,
    SELECT_PARAMETERS,
    PLAY
};
PROGRAM_STATE state;

enum SELECT_STATE
{
    WHITE_BALL,
    TARGET,
    HOLE
};
SELECT_STATE selState;

cv::VideoCapture camera(1);

Vec3 targetColor(29, 227, 218);
Vec3 minColor;
Vec3 maxColor;
Vec3 redColor(1, 227, 218);
Vec3 minRed;
Vec3 maxRed;

Vec3 threshold(30, 80, 80);

std::deque< Flooder::Blob > blobs;

bool running = true;

//Used as a safe way of shutting down the program since ctrl+c doesn't stop
//using the webcam
void onMouse(int event, int x, int y, int, void*);
void selectColor(int event, int x, int y, int , void*);
void setMinMaxColor(Vec3 target, Vec3& minColor, Vec3& maxColor, Vec3 threshold);
void captureNewImage();
void runSelect(float x, float y);

void mainLoop();

std::unique_ptr<CoordinateConverter> coordinateConverter;

cv::Mat currentImage;
ColorTracker ct;

Pool pool;

int main()
{
    //Reading bounds of the table
    std::ifstream boundFile;
    boundFile.open("bounds");

    std::vector<Vec2> boundCoords;
    for(int i = 0; i < 3; ++i)
    {
        float x, y;

        boundFile >> x >> y;

        boundCoords.push_back(Vec2(x, y));
    }
    coordinateConverter.reset(new CoordinateConverter(boundCoords));
    
    if(camera.isOpened() == false)
    {
        std::cout << "Failed to open camera" << std::endl;
    }

    //capture 1 image for use as reference
    cv::Mat ref;
    camera >> ref;

    ColorTracker ct;
    ct.setImage(ref);

    //targetColor = ct.getObjectColor();
    minColor = targetColor - threshold;
    maxColor = targetColor + threshold;
    minRed = redColor - threshold;
    maxRed = redColor + threshold;

    cv::namedWindow("GUI");
    cv::setMouseCallback("GUI", onMouse);
    cv::moveWindow("GUI", 0, 500);

    cv::namedWindow("Display Image");
    cv::setMouseCallback("Display Image", selectColor);

    cv::namedWindow("Threshold img");
    cv::moveWindow("Threshold img", 0, 0);

    while(running == true)
    {
        mainLoop();
    }

    return 0;
}

void mainLoop()
{
    if(state == WAIT_FOR_SELECT)
    {
        captureNewImage();

        //Colortracking
        ct.setImage(currentImage);
        ct.generateBinary(minColor, maxColor, true);

        //Getting the blob data from the trackers
        ct.generateBlobs();
        blobs = ct.getBlobs(60);

        int maxBlobSize = 0;
        auto maxBlob= blobs.begin();
        for(auto it = blobs.begin(); it != blobs.end(); ++it)
        {
            if(it->pixelAmount > maxBlobSize)
            {
                maxBlobSize = it->pixelAmount;
                maxBlob= it;
            }
        }
        blobs.erase(maxBlob);
    }
    else if(state == SELECT_PARAMETERS)
    {

    }<commit_msg>add UI for selecting balls<commit_after>#include <stdio.h>

#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>
#include <time.h>
#include <unistd.h>
#include <memory>

#include "objectTracking/ColorTracker.h"
#include "objectTracking/Flooder.h"
#include "CoordinateConverter.h"
#include "Pool.h"

enum PROGRAM_STATE
{
    WAIT_FOR_SELECT,
    SELECT_PARAMETERS,
    PLAY
};
PROGRAM_STATE state;

enum SELECT_STATE
{
    WHITE_BALL,
    TARGET,
    HOLE
};
SELECT_STATE selState;

cv::VideoCapture camera(1);

Vec3 targetColor(29, 227, 218);
Vec3 minColor;
Vec3 maxColor;
Vec3 redColor(1, 227, 218);
Vec3 minRed;
Vec3 maxRed;

Vec3 threshold(30, 80, 80);

std::deque< Flooder::Blob > blobs;

bool running = true;

//Used as a safe way of shutting down the program since ctrl+c doesn't stop
//using the webcam
void onMouse(int event, int x, int y, int, void*);
void selectColor(int event, int x, int y, int , void*);
void setMinMaxColor(Vec3 target, Vec3& minColor, Vec3& maxColor, Vec3 threshold);
void captureNewImage();
void runSelect(float x, float y);

void mainLoop();

std::unique_ptr<CoordinateConverter> coordinateConverter;

cv::Mat currentImage;
ColorTracker ct;

Pool pool;

int main()
{
    //Reading bounds of the table
    std::ifstream boundFile;
    boundFile.open("bounds");

    std::vector<Vec2> boundCoords;
    for(int i = 0; i < 3; ++i)
    {
        float x, y;

        boundFile >> x >> y;

        boundCoords.push_back(Vec2(x, y));
    }
    coordinateConverter.reset(new CoordinateConverter(boundCoords));
    
    if(camera.isOpened() == false)
    {
        std::cout << "Failed to open camera" << std::endl;
    }

    //capture 1 image for use as reference
    cv::Mat ref;
    camera >> ref;

    ColorTracker ct;
    ct.setImage(ref);

    //targetColor = ct.getObjectColor();
    minColor = targetColor - threshold;
    maxColor = targetColor + threshold;
    minRed = redColor - threshold;
    maxRed = redColor + threshold;

    cv::namedWindow("GUI");
    cv::setMouseCallback("GUI", onMouse);
    cv::moveWindow("GUI", 0, 500);

    cv::namedWindow("Display Image");
    cv::setMouseCallback("Display Image", selectColor);

    cv::namedWindow("Threshold img");
    cv::moveWindow("Threshold img", 0, 0);

    while(running == true)
    {
        mainLoop();
    }

    return 0;
}

void mainLoop()
{
    if(state == WAIT_FOR_SELECT)
    {
        captureNewImage();

        //Colortracking
        ct.setImage(currentImage);
        ct.generateBinary(minColor, maxColor, true);

        //Getting the blob data from the trackers
        ct.generateBlobs();
        blobs = ct.getBlobs(60);

        int maxBlobSize = 0;
        auto maxBlob= blobs.begin();
        for(auto it = blobs.begin(); it != blobs.end(); ++it)
        {
            if(it->pixelAmount > maxBlobSize)
            {
                maxBlobSize = it->pixelAmount;
                maxBlob= it;
            }
        }
        blobs.erase(maxBlob);
    }
    else if(state == SELECT_PARAMETERS)
    {
        std::string instruction;

        float offset = 0;
        switch(selState)
        {
            case WHITE_BALL:
                instruction = "Select white ball";
                break;
            case TARGET:
                instruction = "Select target ball";
                offset = 100;
                break;
            case HOLE:
                instruction = "Select pocket";
                offset = 200;
                break;
        }
        cv::putText(currentImage, instruction, cv::Point(10, 100 + offset), cv::FONT_HERSHEY_DUPLEX, 1, cv::Scalar(255,0,255));
    }
{'fraction_non_alphanumeric': 0.12595936794582394, 'fraction_numerical': 0.017757712565838978, 'mean_word_length': 2.688124306326304, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2079476', 'n_tokens_mistral': 2288, 'n_tokens_neox': 2130, 'n_words': 548}