⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 whitebalancer.h

📁 该程序实现FIRE足球机器人竞赛中的3:3比赛源码
💻 H
字号:
// WhiteBalancer.h: interface for the CWhiteBalancer class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_WHITEBALANCER_H__6DA3D5B4_9A5F_4CEF_AC6C_64B0DDC0FB04__INCLUDED_)
#define AFX_WHITEBALANCER_H__6DA3D5B4_9A5F_4CEF_AC6C_64B0DDC0FB04__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "bcam.h"
#include <math.h>

#pragma warning( disable: 4244 4995 )

//class CMainFrame;

class CWhiteBalancer  
{
public:
  CWhiteBalancer();

  void Init(int ub, int vr);
  bool Next(PBYTE imgBuffer, const CSize& imgSize);

  long GetVRValue() { return m_VR; }
  long GetUBValue() { return m_UB; }


  virtual ~CWhiteBalancer();


  void GetMeans(PBYTE imgBuffer, const CSize& imgSize, double& meanr, double& meang, double& meanb);

  long m_nIterations;
  bool m_fBayerImage;
  bool m_fConverged;
  long m_VR;
  long m_UB;
  long m_Min;
  long m_Max;
  long m_bestUB;
  long m_bestVR;
  double m_minError;
  

protected:

  static const int MAX_ITERATIONS;

  class CBisection
  {
    long m_min;
    long m_max;
    long m_left;
    long m_right;
    static const double THRESH_HIT;
    static const double THRESH_ACCEPT;


  public:

    CBisection()  { Init(0, 100); };

    void Init(long min, long max) { 
      m_min = min; 
      m_max = max; 
      m_left = min;
      m_right = max;
    }
    
    bool Next(const int x, const double y, const double t, long& next) { 
      bool converged = false;


      if ( fabs( t - y ) <= THRESH_HIT )
      {
        converged = true;
        TRACE("hit\n");
        next = x;
        return true;
      } 

      if ( m_left >= m_right )
      {
        next = x;
        converged = true;
        long newLeft, newRight;
        if ( fabs(y - t ) > THRESH_ACCEPT )
        {
          if ( t > y )
          {
            newLeft = x ;
            newRight = newLeft + 0.25 * ( m_max - m_min );
            if ( newRight > m_max )
              newRight = m_max;
          }
          else
          {
            newLeft = x - 0.25 * ( m_max - m_min );
            if ( newLeft < m_min )
              newLeft = m_min;
            newRight = x;
          }
          if ( newRight - newLeft > 1 )
          {
            next = 0.5 * ( m_left + m_right );
            m_left = newLeft;
            m_right = newRight;
            return false;
          }
        } 

        return true;
      }
      
      if ( y < t  )
        m_left = x + 1;
      else
        m_right = x - 1;

      next = 0.5 * ( m_left + m_right );

      return converged;

    }

  };

  CBisection m_VBisection;
  CBisection m_UBisection;
};

#endif // !defined(AFX_WHITEBALANCER_H__6DA3D5B4_9A5F_4CEF_AC6C_64B0DDC0FB04__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -