<commit_before>#include "binarycompiler.h"

#include "../hardware/projector/graycodepattern.h"
#include "triangulator.h"

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

BinaryCompiler::BinaryCompiler(QCamera *cam,
                               QObject *parent) :
    QObject(parent),
    camera(cam)
{
    connect(cam,
            SIGNAL(frameCaptured(cv::Mat,
                                 QCamera*,
                                 QProjector::Pattern*
                                 )),
            this,
            SLOT(frameCaptured(cv::Mat,
                               QCamera*,
                               QProjector::Pattern*
                               )));
}

void BinaryCompiler::requestFrame(uint nmax)
{
    uint n;
    QProjector *projector = camera->getProjector();
    nmax++;
    frames.clear();
    captured.clear();
    frames.resize(nmax*2);
    captured.resize(nmax*2,false);
    for(n=0;n<nmax;n++){
        projector->queue(new GrayCodePattern(n,false));
        projector->queue(new GrayCodePattern(n,true));
    }
}

void BinaryCompiler::frameCaptured(
        cv::Mat frame,
        QCamera *cam,
        QProjector::Pattern *pattern)
{
    GrayCodePattern *gray =
            dynamic_cast<GrayCodePattern*>(pattern);
    uint idx;
    if(cam!=camera || !gray) return;
    idx = (gray->getBit()*2) + (gray->isInverted()?1:0);
    cv::cvtColor(frame,frames.at(idx),CV_BGR2GRAY);
    captured.at(idx) = true;
    std::cout << idx << "\n";
    for(idx=0;idx<captured.size();idx++){
        std::cout << (captured.at(idx)?"#":".");
    }
    std::cout << "\n";
    testAndEmit();
}

void BinaryCompiler::testAndEmit()
{
    uint n, nmax;
    cv::Mat encoding;
    nmax = frames.size()/2;
    for(n=0;n<captured.size();n++){
        if(!captured.at(n)){
            return;
        }
    }
    encoding = Triangulator::computeBinary(
                frames,15);
    emit binaryFrameCaptured(encoding);
    cv::Mat color = Triangulator::maphsv(encoding,
                                         1<<nmax);
    emit visualBinaryFrame(color);
    cv::imwrite("/home/ryan/nubinary.png",color);
}<commit_msg>small tweaks for testing<commit_after>#include "binarycompiler.h"

#include "../hardware/projector/graycodepattern.h"
#include "triangulator.h"

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

BinaryCompiler::BinaryCompiler(QCamera *cam,
                               QObject *parent) :
    QObject(parent),
    camera(cam)
{
    connect(cam,
            SIGNAL(frameCaptured(cv::Mat,
                                 QCamera*,
                                 QProjector::Pattern*
                                 )),
            this,
            SLOT(frameCaptured(cv::Mat,
                               QCamera*,
                               QProjector::Pattern*
                               )));
}

void BinaryCompiler::requestFrame(uint nmax)
{
    uint n;
    QProjector *projector = camera->getProjector();
    nmax++;
    frames.clear();
    captured.clear();
    frames.resize(nmax*2);
    captured.resize(nmax*2,false);
    for(n=0;n<nmax;n++){
        projector->queue(new GrayCodePattern(n,false));
        projector->queue(new GrayCodePattern(n,true));
    }
}

void BinaryCompiler::frameCaptured(
        cv::Mat frame,
        QCamera *cam,
        QProjector::Pattern *pattern)
{
    GrayCodePattern *gray =
            dynamic_cast<GrayCodePattern*>(pattern);
    uint idx;
    if(cam!=camera || !gray) return;
    idx = (gray->getBit()*2) + (gray->isInverted()?1:0);
    cv::cvtColor(frame,frames.at(idx),CV_BGR2GRAY);
    captured.at(idx) = true;
    std::cout << idx << "\n";
    for(idx=0;idx<captured.size();idx++){
        std::cout << (captured.at(idx)?"#":".");
    }
    std::cout << "\n";
    testAndEmit();
}

void BinaryCompiler::testAndEmit()
{
    uint n, nmax;
    cv::Mat encoding;
    nmax = frames.size()/2;
    for(n=0;n<captured.size();n++){
        if(!captured.at(n)){
            return;
        }
    }
    encoding = Triangulator::computeBinary(
                frames,20);
    emit binaryFrameCaptured(encoding);
    cv::Mat color = Triangulator::maphsv(encoding,
                                         1<<nmax);
    emit visualBinaryFrame(color);
    cv::imwrite("/home/ryan/nubinary.png",color);
}
{'fraction_non_alphanumeric': 0.15160482585932164, 'fraction_numerical': 0.0068290462098793536, 'mean_word_length': 2.103107344632768, 'pattern_counts': {'":': 2, '<': 37, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3479061', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1385, 'n_words': 201}