<commit_before>
/**
* @file GradientGoalDetector.cpp
*
* Implementation of class GradientGoalDetector
*
*/

#include "GradientGoalDetector.h"

#include "Tools/DataStructures/ArrayQueue.h"
#include "Tools/CameraGeometry.h"

#include "Tools/Debug/Stopwatch.h"

#include "Tools/ImageProcessing/BresenhamLineScan.h"

#include <Representations/Infrastructure/CameraInfoConstants.h>


GradientGoalDetector::GradientGoalDetector()
: 
  cameraID(CameraInfo::Bottom)
{
  DEBUG_REQUEST_REGISTER("NeoVision:GradientGoalDetector:markPeaks", "mark found maximum u-v peaks in image", false);
  DEBUG_REQUEST_REGISTER("NeoVision:GradientGoalDetector:draw_scanlines","..", false);  
  DEBUG_REQUEST_REGISTER("NeoVision:GradientGoalDetector:draw_response","..", false);  
  DEBUG_REQUEST_REGISTER("NeoVision:GradientGoalDetector:draw_difference","..", false);  
  DEBUG_REQUEST_REGISTER("NeoVision:GradientGoalDetector:markFootScans","..", false);  
  DEBUG_REQUEST_REGISTER("NeoVision:GradientGoalDetector:markFootScanGoodPoints","..", false);  
}


void GradientGoalDetector::execute(CameraInfo::CameraID id)
{
  cameraID = id;
  CANVAS_PX(cameraID);

  getGoalPercept().reset();

  Vector2<double> p1(getArtificialHorizon().begin());
  Vector2<double> p2(getArtificialHorizon().end());

  Vector2<double> direction = getArtificialHorizon().getDirection();
  
  //double horizont = min(p1.y, p2.y);

  double threshold = params.gradientThreshold;
  double thresholdY = params.minY;

  Pixel pixel;

  int aktIdx = 0;

  for(int i = 0; i < 5; i++)
  {
     features[i].clear();
  }

  if(p1.y > 15 && p2.y > 15 && p1.y < (int) getImage().height() - 15 && p2.y < (int) getImage().height() - 15)
  {
    double response = 0.0;
    double responseY = 0.0;
    double lastResponse = 0.0;
    double lastResponseY = 0.0;
    bool isCandidate = false;
    bool isObstacle = false;
    
    Feature candidate;

    int diffVU = 0;
    int lastDiffVU = 0;

    for(int y = (int) p1.y - 12; y <= (int) p1.y + 12; y += 6)
    {
      valueBuffer.init();
      valueBufferY.init();
      pointBuffer.init();
      isCandidate = false;
      Vector2<int> pos((int) p1.x + 2, y);
      BresenhamLineScan scanner(pos, direction, getImage().cameraInfo);
      do
      {
        pointBuffer.add(pos);
        getImage().get(pos.x, pos.y, pixel);
        diffVU = (int) pixel.v - (int) pixel.u;
        valueBuffer.add(diffVU);
        valueBufferY.add(pixel.y);<commit_msg>scan in the top of the image if the image is below it<commit_after>
/**
* @file GradientGoalDetector.cpp
*
* Implementation of class GradientGoalDetector
*
*/

#include "GradientGoalDetector.h"

#include "Tools/DataStructures/ArrayQueue.h"
#include "Tools/CameraGeometry.h"

#include "Tools/Debug/Stopwatch.h"

#include "Tools/ImageProcessing/BresenhamLineScan.h"

#include <Representations/Infrastructure/CameraInfoConstants.h>


GradientGoalDetector::GradientGoalDetector()
: 
  cameraID(CameraInfo::Bottom)
{
  DEBUG_REQUEST_REGISTER("NeoVision:GradientGoalDetector:markPeaks", "mark found maximum u-v peaks in image", false);
  DEBUG_REQUEST_REGISTER("NeoVision:GradientGoalDetector:draw_scanlines","..", false);  
  DEBUG_REQUEST_REGISTER("NeoVision:GradientGoalDetector:draw_response","..", false);  
  DEBUG_REQUEST_REGISTER("NeoVision:GradientGoalDetector:draw_difference","..", false);  
  DEBUG_REQUEST_REGISTER("NeoVision:GradientGoalDetector:markFootScans","..", false);  
  DEBUG_REQUEST_REGISTER("NeoVision:GradientGoalDetector:markFootScanGoodPoints","..", false);  
}


void GradientGoalDetector::execute(CameraInfo::CameraID id)
{
  cameraID = id;
  CANVAS_PX(cameraID);

  getGoalPercept().reset();

  Vector2d p1(getArtificialHorizon().begin());
  Vector2d p2(getArtificialHorizon().end());
  Vector2d direction = getArtificialHorizon().getDirection();
  
  int imageBorderOffset = 15;
  int heightOfHorizon = (int)((p1.y + p2.y) * 0.5 + 0.5);
  // image over the horizon
  if(heightOfHorizon > (int)getImage().cameraInfo.resolutionHeight-10) { 
    return;
  }

  // adjust the scan height in case of the bottom camera
  if(cameraID == CameraInfo::Bottom) {
    // clamp the scanline
    p1.y = Math::clamp((int)p1.y, imageBorderOffset+5, (int)getImage().cameraInfo.resolutionHeight-imageBorderOffset-5);
    p2.y = Math::clamp((int)p2.y, imageBorderOffset+5, (int)getImage().cameraInfo.resolutionHeight-imageBorderOffset-5);
  }

  //double horizont = min(p1.y, p2.y);

  double threshold = params.gradientThreshold;
  double thresholdY = params.minY;

  Pixel pixel;

  int aktIdx = 0;

  for(int i = 0; i < 5; i++)
  {
     features[i].clear();
  }

  if(p1.y > imageBorderOffset && 
     p2.y > imageBorderOffset && 
     p1.y < (int) getImage().height() - imageBorderOffset && 
     p2.y < (int) getImage().height() - imageBorderOffset)
  {
    double response = 0.0;
    double responseY = 0.0;
    double lastResponse = 0.0;
    double lastResponseY = 0.0;
    bool isCandidate = false;
    bool isObstacle = false;
    
    Feature candidate;

    int diffVU = 0;
    int lastDiffVU = 0;

    for(int y = (int) p1.y - 12; y <= (int) p1.y + 12; y += 6)
    {
      valueBuffer.init();
      valueBufferY.init();
      pointBuffer.init();
      isCandidate = false;
      Vector2<int> pos((int) p1.x + 2, y);
      BresenhamLineScan scanner(pos, direction, getImage().cameraInfo);
      do
      {
        pointBuffer.add(pos);
        getImage().get(pos.x, pos.y, pixel);
        diffVU = (int) pixel.v - (int) pixel.u;
        valueBuffer.add(diffVU);
        valueBufferY.add(pixel.y);
{'fraction_non_alphanumeric': 0.14146868250539957, 'fraction_numerical': 0.016918646508279338, 'mean_word_length': 3.9395555555555557, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 15, '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': '3321424', 'n_tokens_mistral': 2032, 'n_tokens_neox': 1924, 'n_words': 352}