<commit_before>//
//  cvTracker.cpp
//  multiIPCameTracker
//
//  Created by <NAME> on 9/1/15.
//
//

#include "cvTracker.h"
void cvTracker::setup(int width, int height)
{
    fbo.allocate(width,height,GL_RGB);
    pixels.allocate(width,height,OF_IMAGE_COLOR);
    
    
    opticalFlow.setup(ofRectangle(0, 0, width, height));
    cvImage.allocate(width, height);
    grayImage.allocate(width, height);
    opticalFlow.setOpticalFlowSize(14);
    opticalFlow.setOpticalFlowBlur(14);
    grayBg.allocate(width,height);
    grayDiff.allocate(width,height);
    trackerControl = ofPtr<ofParameterGroup>(new ofParameterGroup);
    threshold = ofPtr<ofParameter<int> > (new ofParameter<int>);
    minArea = ofPtr<ofParameter<int> > (new ofParameter<int>);
    maxArea = ofPtr<ofParameter<int> > (new ofParameter<int>);
    nConsidered = ofPtr<ofParameter<int> > (new ofParameter<int>);
    bFindHoles = ofPtr<ofParameter<bool> > (new ofParameter<bool>);
    bUseApproximation  = ofPtr<ofParameter<bool> > (new ofParameter<bool>);
    bBlur = ofPtr<ofParameter<bool> > (new ofParameter<bool>);
    trackerControl->setName("CV opticalFlow Tracking");
    trackerControl->add( threshold->set("threashold",80,1,255));
    trackerControl->add( minArea->set("minArea",20,20,width*height));
    trackerControl->add( maxArea->set("maxArea",80,20,width*height));
    trackerControl->add( nConsidered->set("nConsidered",10,1,100));
    trackerControl->add( bFindHoles->set("bFindHoles",true));
    trackerControl->add( bUseApproximation->set("bUseApproximation",true));
    trackerControl->add( bBlur->set("bBlur",true));
    
    sender.setup(HOST, PORT);
}
void cvTracker::update(ofFbo &infbo, int width, int height)
{
    if(!incoming_pixels.isAllocated())
    {
        incoming_pixels.allocate(infbo.getWidth(), infbo.getHeight(), OF_IMAGE_COLOR);
    }
    infbo.readToPixels(incoming_pixels);
    opticalFlow.update(incoming_pixels.getPixels() , incoming_pixels.getWidth(), incoming_pixels.getHeight() , OF_IMAGE_COLOR);
    fbo.begin();
    ofPushStyle();
    ofSetColor(0);
    ofFill();
    ofRect(0, 0, width,height);
    ofPopStyle();
    ofSetColor(255);
//    infbo.draw(0,0,width,height);
    opticalFlow.draw(width,height,5,4);
    fbo.end();
    fbo.readToPixels(pixels);
    cvImage.setFromPixels(pixels.getPixels(), width,height);
    grayImage = cvImage;
    
    if(bBlur)grayImage.blur();
    
    
    
    
    // take the abs value of the difference between background and incoming and then threshold:
    grayDiff.absDiff(grayBg, grayImage);
    grayDiff.threshold(threshold->get());
    
    // find contours which are between the size of 20 pixels and 1/3 the w*h pixels.
    // also, find holes is set to true so we will get interior contours as well....
    contourFinder.findContours(grayImage,
                               minArea->get(),
                               maxArea->get(),
                               nConsidered->get(),
                               bFindHoles->get(),
                               bUseApproximation->get());	// find holes
    
    grayBg = grayImage;
//    ofxOscBundle bundle;
//    ofxOscMessage m;
    if(contourFinder.nBlobs>0)
    {
        ofxOscBundle bundle;
        for (int i = 0; i < contourFinder.nBlobs; i++){
            ofxOscMessage m;
            m.setAddress("/contour");
            m.addFloatArg(contourFinder.blobs[i].boundingRect.getCenter().x);
            m.addFloatArg(contourFinder.blobs[i].boundingRect.getCenter().y);
            sender.sendMessage(m);
            bundle.addMessage(m);
        }
         sender.sendBundle(bundle);
    }
   

}<commit_msg>update Bosc<commit_after>//
//  cvTracker.cpp
//  multiIPCameTracker
//
//  Created by <NAME> on 9/1/15.
//
//

#include "cvTracker.h"
void cvTracker::setup(int width, int height)
{
    fbo.allocate(width,height,GL_RGB);
    pixels.allocate(width,height,OF_IMAGE_COLOR);
    
    opticalFlow.setup(ofRectangle(0, 0, width, height));
    cvImage.allocate(width, height);
    grayImage.allocate(width, height);
    opticalFlow.setOpticalFlowSize(14);
    opticalFlow.setOpticalFlowBlur(14);
    grayBg.allocate(width,height);
    grayDiff.allocate(width,height);
    trackerControl = ofPtr<ofParameterGroup>(new ofParameterGroup);
    threshold = ofPtr<ofParameter<int> > (new ofParameter<int>);
    minArea = ofPtr<ofParameter<int> > (new ofParameter<int>);
    maxArea = ofPtr<ofParameter<int> > (new ofParameter<int>);
    nConsidered = ofPtr<ofParameter<int> > (new ofParameter<int>);
    bFindHoles = ofPtr<ofParameter<bool> > (new ofParameter<bool>);
    bUseApproximation  = ofPtr<ofParameter<bool> > (new ofParameter<bool>);
    bBlur = ofPtr<ofParameter<bool> > (new ofParameter<bool>);
    trackerControl->setName("CV opticalFlow Tracking");
    trackerControl->add( threshold->set("threashold",80,1,255));
    trackerControl->add( minArea->set("minArea",20,20,width*height));
    trackerControl->add( maxArea->set("maxArea",80,20,width*height));
    trackerControl->add( nConsidered->set("nConsidered",10,1,100));
    trackerControl->add( bFindHoles->set("bFindHoles",true));
    trackerControl->add( bUseApproximation->set("bUseApproximation",true));
    trackerControl->add( bBlur->set("bBlur",true));
    
    sender.setup(HOST, PORT);
}
void cvTracker::update(ofFbo &infbo, int width, int height)
{
    if(!incoming_pixels.isAllocated())
    {
        incoming_pixels.allocate(infbo.getWidth(), infbo.getHeight(), OF_IMAGE_COLOR);
    }
    infbo.readToPixels(incoming_pixels);
    try
    {
    opticalFlow.update(incoming_pixels.getPixels() , incoming_pixels.getWidth(), incoming_pixels.getHeight() , OF_IMAGE_COLOR);
    }
    catch(exception e)
    {
        ofLogVerbose() << e;
    }
    fbo.begin();
    ofPushStyle();
    ofSetColor(0);
    ofFill();
    ofRect(0, 0, width,height);
    ofPopStyle();
    ofSetColor(255);
//    infbo.draw(0,0,width,height);
    opticalFlow.draw(width,height,5,4);
    fbo.end();
    fbo.readToPixels(pixels);
    cvImage.setFromPixels(pixels.getPixels(), width,height);
    grayImage = cvImage;
    
    if(bBlur)grayImage.blur();
    
    
    
    
    // take the abs value of the difference between background and incoming and then threshold:
    grayDiff.absDiff(grayBg, grayImage);
    grayDiff.threshold(threshold->get());
    
    // find contours which are between the size of 20 pixels and 1/3 the w*h pixels.
    // also, find holes is set to true so we will get interior contours as well....
    contourFinder.findContours(grayImage,
                               minArea->get(),
                               maxArea->get(),
                               nConsidered->get(),
                               bFindHoles->get(),
                               bUseApproximation->get());	// find holes
    
    grayBg = grayImage;
//    ofxOscBundle bundle;
//    ofxOscMessage m;
    if(contourFinder.nBlobs>0)
    {
        ofParameterGroup pGroup;
//        ofxOscBundle bundle;
        for (int i = 0; i < contourFinder.nBlobs; i++){
//            ofxOscMessage m;
//            m.setAddress("/contour");
            
//            m.addFloatArg(contourFinder.blobs[i].boundingRect.getCenter().x);
//            m.addFloatArg(contourFinder.blobs[i].boundingRect.getCenter().y);
//            sender.sendMessage(m);
//            bundle.addMessage(m);

//            ofxOscMessage m_hue;
//            m_hue.setAddress("/hue");
//            m_hue.addIntArg(c.getHue());
//            bundle.addMessage(m_hue);
            ofParameter<ofColor>color;
            ofParameter<ofVec2f>v2;
            pGroup.add(v2.set("contour", contourFinder.blobs[i].boundingRect.getCenter()));
            pGroup.add(color.set("color", incoming_pixels.getColor(contourFinder.blobs[i].boundingRect.getCenter().x, contourFinder.blobs[i].boundingRect.getCenter().x)));

        }
//         sender.sendBundle(bundle);
        sender.sendParameter(pGroup);
    }
   

}
{'fraction_non_alphanumeric': 0.14195979899497488, 'fraction_numerical': 0.01193467336683417, 'mean_word_length': 2.9508684863523573, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 95, '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': '5065838', 'n_tokens_mistral': 2677, 'n_tokens_neox': 2609, 'n_words': 405}