Beispiel #1
0
void DetectFaces(          // all face rects into detpars
    vec_DetPar&  detpars,  // out
    const Image& img,      // in
    int          minwidth) // in: as percent of img width
{
    CV_Assert(!facedet_g.empty()); // check that OpenFaceDetector_ was called

    int leftborder = 0, topborder = 0; // border size in pixels
    Image bordered_img(BORDER_FRAC == 0?
                       img: EnborderImg(leftborder, topborder, img));

    // Detection results are very slightly better with equalization
    // (tested on the MUCT images, which are not pre-equalized), and
    // it's quick enough to equalize (roughly 10ms on a 1.6 GHz laptop).

    Image equalized_img;
    cv::equalizeHist(bordered_img, equalized_img);

    CV_Assert(minwidth >= 1 && minwidth <= 100);

    // TODO smallest bioid faces are about 80 pixels width, hence 70 below
    const int minpix =
        MAX(minwidth <= 5? 70: 100, cvRound(img.cols * minwidth / 100.));

    // the params below are accurate but slow
    static const double SCALE_FACTOR   = 1.1;
    static const int    MIN_NEIGHBORS  = 3;
    static const int    DETECTOR_FLAGS = 0;

    vec_Rect facerects = // all face rects in image
        Detect(equalized_img, facedet_g, NULL,
               SCALE_FACTOR, MIN_NEIGHBORS, DETECTOR_FLAGS, minpix);

    // copy face rects into the detpars vector

    detpars.resize(NSIZE(facerects));
    for (int i = 0; i < NSIZE(facerects); i++)
    {
        Rect* facerect = &facerects[i];
        DetPar detpar; // detpar constructor sets all fields INVALID
        // detpar.x and detpar.y is the center of the face rectangle
        detpar.x = facerect->x + facerect->width / 2.;
        detpar.y = facerect->y + facerect->height / 2.;
        detpar.x -= leftborder; // discount the border we added earlier
        detpar.y -= topborder;
        detpar.width  = double(facerect->width);
        detpar.height = double(facerect->height);
        detpar.yaw = 0; // assume face has no yaw in this version of Stasm
        detpar.eyaw = EYAW00;
        detpars[i] = detpar;
    }
}
Beispiel #2
0
bool CTarget::GetTooltip(Math::Point pos, std::string &name)
{
    if ( (m_state & STATE_VISIBLE) == 0 )  return false;

    if ( (m_state&STATE_VISIBLE) && Detect(pos) )  // in the window?
    {
        if ( !m_main->GetFriendAim() )
        {
            m_tooltip = name;
            return true;  // does not detect objects below!
        }
    }

    return false;
}
	static inline void EncoderCapture()
	{
		uint8_t y1 = EncRead1();
		uint8_t y2 = EncRead2();

		uint8_t fwd  = Detect(_x1, _x2, y1, y2);
		uint8_t back = Detect(_x2, _x1, y2, y1);

		_x1 = y1;
		_x2 = y2;

		volatile EncValueType * ptr = EncoderValues;
		for(uint8_t i = EncoderChannels; i; --i)
		{	
			if(fwd & 1)
				 (*ptr) ++;
			else 
			if(back & 1)
				(*ptr) --;
			ptr++;
			fwd >>= 1;
			back >>= 1;
		}
	}
Beispiel #4
0
void Blink::TrackEyes(IplImage* newFrame, IplImage* mask)
{
	if(!oriImage) oriImage=(IplImage*)cvClone(newFrame);
	else cvCopy(newFrame,oriImage,NULL);

	IplImage* temp=(IplImage*)cvClone(newFrame);
	if(mask!=NULL) cvAnd(newFrame,mask,temp);

	if(leftEyeTracker && rightEyeTracker){
		leftEye=leftEyeTracker->getNextLocation(temp);
		rightEye=rightEyeTracker->getNextLocation(temp);
	}
	else{
		Detect(temp);
	}
}
Beispiel #5
0
MainWindow::MainWindow() : QMainWindow()
{
//  settings_ = settings;
  ui.setupUi(this);
  qml_Page_ = new QDeclarativeView;
  qml_Page_->setSource(QUrl("qrc:///ui/Checkerboard.qml"));
  qml_Page_->setResizeMode(QDeclarativeView::SizeRootObjectToView);

  this->game_page_ = new ViewManager();

  QGraphicsObject *background = qml_Page_->rootObject();

//  connect(background, SIGNAL(sizeChanged(int, int)),
//          this, SIGNAL(sizeChanged(int, int)));
//  connect(background, SIGNAL(calibrate()),
//          this, SIGNAL(calibrate()));
//  connect(background, SIGNAL(sizeChanged(int,int)),
//          this, SLOT(UiSizeChanged()));
//  connect(background, SIGNAL(resize()),
//          this, SLOT(Resize()));
//  connect(background, SIGNAL(detect()),
//          this, SIGNAL(detect()));
//  connect(background, SIGNAL(screencap()),
//          this, SLOT(TakeScreenshot()));
  connect(ui.Detect, SIGNAL(clicked()),
          this, SIGNAL(Detect()));
  connect(ui.Calibration, SIGNAL(clicked()),
          this, SIGNAL(Calibrate()));
  connect(ui.Toggle, SIGNAL(clicked()),
          this, SLOT(Toggle()));
  connect(ui.DiceRegister, SIGNAL(clicked()),
          this, SIGNAL(DiceRegisterSetup()));

  connect(background, SIGNAL(sizeChanged(int,int)),
          this, SIGNAL(sizeChanged(int,int)));
  connect(background, SIGNAL(sizeChanged(int,int)),
          this, SLOT(UiSizeChanged()));

  this->readSettings();
  emit ( sizeChanged( this->width()/150, this->height()/150));

//  setCentralWidget(this->qml_page);
  ui.stackedWidget->addWidget(qml_Page_);
  ui.stackedWidget->addWidget(game_page_);
  ui.stackedWidget->setCurrentWidget(qml_Page_);
}
Beispiel #6
0
static void DetectAllMouths(
    vec_Rect&       mouths,           // out: a vector of detected mouths
    const Image&    img,              // in
    const Rect&     facerect,         // in: the detected face rectangle
    const Rect&     mouth_searchrect) // in
{
    CV_Assert(!mouth_det_g.empty()); // detector initialized?

    static const double MOUTH_SCALE_FACTOR   = 1.2; // less false pos with 1.2 than 1.1
    static const int    MOUTH_MIN_NEIGHBORS  = 5;   // less false pos with 5 than 3
    static const int    MOUTH_DETECTOR_FLAGS = 0;

    mouths =
        Detect(img, mouth_det_g, &mouth_searchrect,
               MOUTH_SCALE_FACTOR, MOUTH_MIN_NEIGHBORS, MOUTH_DETECTOR_FLAGS,
               facerect.width / 10);
}
// Tests the specified filename to see if it is a supported ISO type.  This function typically
// executes faster than isoFile::Open since it does not do the following:
//  * check for multi-part ISOs.  I tests for header info in the main/root ISO only.
//  * load blockdump indexes.
//
// Note that this is a member method, and that it will clobber any existing ISO state.
// (assertions are generated in debug mode if the object state is not already closed).
bool isoFile::Test( const wxString& srcfile )
{
	pxAssertMsg( !m_parts[0].handle, "Warning!  isoFile::Test is about to clobber whatever existing iso bound to this isoFile object!" );

	Close();
	m_filename = srcfile;

	m_parts[0].handle = new wxFileInputStream( m_filename );
	pxStream_OpenCheck( *m_parts[0].handle, m_filename, L"reading" );

	m_numparts		= 1;
	m_parts[0].slsn = 0;

	// elsn is unknown at this time, but is also unused when m_numparts == 1.
	// (and if numparts is incremented, elsn will get assigned accordingly)

	return Detect( false );
}
Beispiel #8
0
bool CKey::EventProcess(const Event &event)
{
    if (m_state & STATE_DEAD)
        return true;

    CControl::EventProcess(event);

    if (event.type == EVENT_MOUSE_BUTTON_DOWN)
    {
        if (event.mouseButton.button == MOUSE_BUTTON_LEFT) // left
            m_catch = Detect(event.mousePos);
    }

    if (event.type == EVENT_KEY_DOWN && m_catch)
    {
        m_catch = false;

        if (TestKey(event.key.key)) // impossible ?
        {
            m_sound->Play(SOUND_TZOING);
        }
        else
        {
            if (event.key.key == m_binding.primary || event.key.key == m_binding.secondary)
            {
                m_binding.secondary = KEY_INVALID;
                m_binding.primary = event.key.key;
            }
            else
            {
                m_binding.secondary = m_binding.primary;
                m_binding.primary = event.key.key;
            }
            m_sound->Play(SOUND_CLICK);

            Event newEvent = event;
            newEvent.type = m_eventType;
            m_event->AddEvent(newEvent);
        }
        return false;
    }

    return true;
}
Beispiel #9
0
static void DetectAllMouths(
    vec_Rect&       mouths,      // out
    const Image&    img,         // in
    EYAW            eyaw,        // in
    const Rect&     facerect,    // in
    int             ileft_best,  // in
    int             iright_best, // in
    const vec_Rect& leyes,       // in
    const vec_Rect& reyes)       // in
{
    CV_Assert(!mouth_det_g.empty()); // detector initialized?

    static const double MOUTH_SCALE_FACTOR   = 1.2; // less false pos with 1.2 than 1.1
    static const int    MOUTH_MIN_NEIGHBORS  = 5;   // less false pos with 5 than 3
    static const int    MOUTH_DETECTOR_FLAGS = 0;

    Rect mouth_rect(MouthRect(facerect,
                              eyaw, ileft_best, iright_best, leyes, reyes));

    mouths =
        Detect(img, &mouth_det_g, &mouth_rect,
               MOUTH_SCALE_FACTOR, MOUTH_MIN_NEIGHBORS, MOUTH_DETECTOR_FLAGS,
               facerect.width / 10);
}
Beispiel #10
0
CPUInfo::CPUInfo()
{
	Detect();
}
Beispiel #11
0
void NoseDetector:: run(){

	Detect();
}
Beispiel #12
0
void CI2CShell::Run (void)
{
	Print ("\n\nI2C Shell\n"
	       "Using master #%u\n"
	       "Default clock rate is %u KHz\n"
	       "Enter \"help\" for help!\n\n",
	       CMachineInfo::Get ()->GetDevice (DeviceI2CMaster),
	       m_nI2CClockHz / 1000);

	while (m_bContinue)
	{
		ReadLine ();

		CString Command;
		while (GetToken (&Command))
		{
			if (((const char *) Command)[0] == '#')
			{
				break;
			}
			else if (Command.Compare ("slave") == 0)
			{
				if (!Slave ())
				{
					break;
				}
			}
			else if (Command.Compare ("clock") == 0)
			{
				if (!Clock ())
				{
					break;
				}
			}
			else if (Command.Compare ("detect") == 0)
			{
				if (!Detect ())
				{
					break;
				}
			}
			else if (   Command.Compare ("read") == 0
				 || Command.Compare ("rd") == 0)
			{
				if (!Read ())
				{
					break;
				}
			}
			else if (   Command.Compare ("write") == 0
				 || Command.Compare ("wr") == 0)
			{
				if (!Write ())
				{
					break;
				}
			}
			else if (Command.Compare ("delay") == 0)
			{
				if (!Delay ())
				{
					break;
				}
			}
			else if (Command.Compare ("reboot") == 0)
			{
				m_bContinue = FALSE;
			}
			else if (Command.Compare ("help") == 0)
			{
				Print (HelpMsg);
			}
			else
			{
				Print ("Unknown command: %s\n", (const char *) Command);
				break;
			}
		}
	}
}
Beispiel #13
0
bool CScroll::EventProcess(const Event &event)
{
    Math::Point pos, dim;
    float   hButton, h, value;

    CControl::EventProcess(event);

    if ( m_buttonUp != 0 && !m_bCapture )
    {
        if ( !m_buttonUp->EventProcess(event) )  return false;
    }
    if ( m_buttonDown != 0 && !m_bCapture )
    {
        if ( !m_buttonDown->EventProcess(event) )  return false;
    }

    if ( event.type == m_eventUp && m_step > 0.0f )
    {
        m_visibleValue -= m_step;
        if ( m_visibleValue < 0.0f )  m_visibleValue = 0.0f;
        AdjustGlint();

        Event newEvent = event;
        newEvent.type = m_eventType;
        m_event->AddEvent(newEvent);
    }

    if ( event.type == m_eventDown && m_step > 0.0f )
    {
        m_visibleValue += m_step;
        if ( m_visibleValue > 1.0f )  m_visibleValue = 1.0f;
        AdjustGlint();

        Event newEvent = event;
        newEvent.type = m_eventType;
        m_event->AddEvent(newEvent);
    }

    hButton = m_buttonUp?m_dim.x/0.75f:0.0f;

    if ( event.type == EVENT_MOUSE_BUTTON_DOWN &&
            event.mouseButton.button == MOUSE_BUTTON_LEFT &&
         (m_state & STATE_VISIBLE)        &&
         (m_state & STATE_ENABLE)         )
    {
        if ( CControl::Detect(event.mousePos) )
        {
            pos.y = m_pos.y+hButton;
            dim.y = m_dim.y-hButton*2.0f;
            pos.y += dim.y*(1.0f-m_visibleRatio)*(1.0f-m_visibleValue);
            dim.y *= m_visibleRatio;
            if ( event.mousePos.y < pos.y       ||
                 event.mousePos.y > pos.y+dim.y )  // click outside cabin?
            {
                h = (m_dim.y-hButton*2.0f)*(1.0f-m_visibleRatio);
                value = 1.0f-(event.mousePos.y-(m_pos.y+hButton+dim.y*0.5f))/h;
                if ( value < 0.0f )  value = 0.0f;
                if ( value > 1.0f )  value = 1.0f;
                m_visibleValue = value;
                AdjustGlint();

                Event newEvent = event;
                newEvent.type = m_eventType;
                m_event->AddEvent(newEvent);
            }
            m_bCapture = true;
            m_pressPos = event.mousePos;
            m_pressValue = m_visibleValue;
        }
    }

    if ( event.type == EVENT_MOUSE_MOVE && m_bCapture )
    {
        h = (m_dim.y-hButton*2.0f)*(1.0f-m_visibleRatio);
        if ( h != 0 )
        {
            value = m_pressValue - (event.mousePos.y-m_pressPos.y)/h;
            if ( value < 0.0f )  value = 0.0f;
            if ( value > 1.0f )  value = 1.0f;

            if ( value != m_visibleValue )
            {
                m_visibleValue = value;
                AdjustGlint();

                Event newEvent = event;
                newEvent.type = m_eventType;
                m_event->AddEvent(newEvent);
            }
        }
    }

    if ( event.type == EVENT_MOUSE_BUTTON_UP &&
            event.mouseButton.button == MOUSE_BUTTON_LEFT &&
            m_bCapture )
    {
        m_bCapture = false;
    }

    if (event.type == EVENT_MOUSE_WHEEL &&
        event.mouseWheel.dir == WHEEL_UP &&
        Detect(event.mousePos) &&
        m_buttonUp != 0)
    {
        Event newEvent = event;
        newEvent.type = m_buttonUp->GetEventType();
        m_event->AddEvent(newEvent);
    }
    if (event.type == EVENT_MOUSE_WHEEL &&
        event.mouseWheel.dir == WHEEL_DOWN &&
        Detect(event.mousePos) &&
        m_buttonDown != 0)
    {
        Event newEvent = event;
        newEvent.type = m_buttonDown->GetEventType();
        m_event->AddEvent(newEvent);
    }

    return true;
}
Beispiel #14
0
void EyeDetector:: run(){

	Detect();
}
Beispiel #15
0
bool CSlider::EventProcess(const Event &event)
{
    Math::Point pos, dim;
    float   value;

    if ( (m_state & STATE_VISIBLE) == 0 )  return true;

    CControl::EventProcess(event);

    if (m_buttonLeft != nullptr && !m_bCapture)
    {
        if ( !m_buttonLeft->EventProcess(event) )  return false;
    }
    if (m_buttonRight != nullptr && !m_bCapture)
    {
        if ( !m_buttonRight->EventProcess(event) )  return false;
    }

    if (m_buttonLeft != nullptr && event.type == m_buttonLeft->GetEventType() && m_step > 0.0f )
    {
        m_visibleValue -= m_bHoriz?m_step:-m_step;
        if ( m_visibleValue < 0.0f )  m_visibleValue = 0.0f;
        if ( m_visibleValue > 1.0f )  m_visibleValue = 1.0f;
        AdjustGlint();

        m_event->AddEvent(Event(m_eventType));
    }

    if (m_buttonRight != nullptr && event.type == m_buttonRight->GetEventType() && m_step > 0.0f )
    {
        m_visibleValue += m_bHoriz?m_step:-m_step;
        if ( m_visibleValue < 0.0f )  m_visibleValue = 0.0f;
        if ( m_visibleValue > 1.0f )  m_visibleValue = 1.0f;
        AdjustGlint();

        m_event->AddEvent(Event(m_eventType));
    }

    if (event.type == EVENT_MOUSE_BUTTON_DOWN &&
        event.GetData<MouseButtonEventData>()->button == MOUSE_BUTTON_LEFT &&
        (m_state & STATE_VISIBLE) &&
        (m_state & STATE_ENABLE))
    {
        if ( CControl::Detect(event.mousePos) )
        {
            if ( m_bHoriz )
            {
                pos.x = m_pos.x+m_marginButton;
                dim.x = m_dim.x-m_marginButton*2.0f;
                value = (event.mousePos.x-pos.x-CURSOR_WIDTH/2.0f);
                value /= (dim.x-CURSOR_WIDTH);
            }
            else
            {
                pos.y = m_pos.y+m_marginButton;
                dim.y = m_dim.y-m_marginButton*2.0f;
                value = (event.mousePos.y-pos.y-CURSOR_WIDTH/2.0f);
                value /= (dim.y-CURSOR_WIDTH);
            }
            if ( value < 0.0f )  value = 0.0f;
            if ( value > 1.0f )  value = 1.0f;
            m_visibleValue = value;
            AdjustGlint();

            m_event->AddEvent(Event(m_eventType));

            m_bCapture = true;
            m_pressPos = event.mousePos;
            m_pressValue = m_visibleValue;
        }
    }

    if ( event.type == EVENT_MOUSE_MOVE && m_bCapture )
    {
        if ( m_bHoriz )
        {
            pos.x = m_pos.x+m_marginButton;
            dim.x = m_dim.x-m_marginButton*2.0f;
            value = (event.mousePos.x-pos.x-CURSOR_WIDTH/2.0f);
            value /= (dim.x-CURSOR_WIDTH);
        }
        else
        {
            pos.y = m_pos.y+m_marginButton;
            dim.y = m_dim.y-m_marginButton*2.0f;
            value = (event.mousePos.y-pos.y-CURSOR_WIDTH/2.0f);
            value /= (dim.y-CURSOR_WIDTH);
        }
        if ( value < 0.0f )  value = 0.0f;
        if ( value > 1.0f )  value = 1.0f;

        if ( value != m_visibleValue )
        {
            m_visibleValue = value;
            AdjustGlint();

            m_event->AddEvent(Event(m_eventType));
        }
    }

    if (event.type == EVENT_MOUSE_BUTTON_UP &&
        event.GetData<MouseButtonEventData>()->button == MOUSE_BUTTON_LEFT  &&
        m_bCapture)
    {
        m_bCapture = false;
    }

    if (event.type == EVENT_MOUSE_WHEEL &&
        event.GetData<MouseWheelEventData>()->dir == WHEEL_UP &&
        Detect(event.mousePos) &&
        m_buttonLeft != nullptr)
    {
        m_event->AddEvent(Event(m_buttonLeft->GetEventType()));
    }

    if (event.type == EVENT_MOUSE_WHEEL &&
        event.GetData<MouseWheelEventData>()->dir == WHEEL_DOWN &&
        Detect(event.mousePos) &&
        m_buttonRight != nullptr)
    {
        m_event->AddEvent(Event(m_buttonRight->GetEventType()));
    }

    return true;
}
Beispiel #16
0
			/**
			 *	Attempts to detect the endianness of a sequence
			 *	of bytes.
			 *
			 *	\param [in] begin
			 *		An iterator to the beginning of the sequence
			 *		of bytes.
			 *	\param [in] end
			 *		An iterator to the end of the sequence of bytes.
			 *
			 *	\return
			 *		An engaged optional containing the detected
			 *		endianness on success, a disengaged optional
			 *		otherwise.
			 */
			std::optional<Endianness> Detect (const void * const & begin, const void * end) const noexcept {
			
				const void * b=begin;
				return Detect(b,end);
			
			}
Beispiel #17
0
int
main( int ArgC, char *ArgV[] )
{
  int BDMHandle;
  unsigned int Base;
  unsigned int Chips;
  unsigned int Bytes;
  char *Operation;
  FlashError_t Error;

  if (ArgC < 6)
    Usage( ArgV[0] );

  if((BDMHandle = bdm_init(ArgV[1]))<0) 
      {
	  fprintf( stderr, 
		   "Problem opening bdm device %s, error code %d.\n", ArgV[1], BDMHandle );
	  return (EXIT_FAILURE);
      }

  Base = (unsigned int) strtoul( ArgV[2], NULL, 0 );
  Chips = (unsigned int) strtoul( ArgV[3], NULL, 0 );
  Bytes = (unsigned int) strtoul( ArgV[4], NULL, 0 );
  Operation = ArgV[5];

  Error = BDMFlashConfigSet( BDMHandle, Base, Chips, Bytes );
  if (Error != FlashErrorOkay_c)
    {
      fprintf( stderr, 
	       "Problem configuring flash; error code = %d '%s'.\n", 
	       (int) Error,
	       FlashErrorDescriptionEnglish[Error] );
    }

  if (strcasecmp( Operation, "erase" ) == 0)
    {
	Erase( ArgC, ArgV );
    }
  else if (strcasecmp( Operation, "SectorErase" ) == 0)
    {
	SectorErase( ArgC, ArgV );
    }
  else if (strcasecmp( Operation, "BlockErase" ) == 0)
    {
	BlockErase( ArgC, ArgV );
    }
  else if (strcasecmp( Operation, "write" ) == 0)
    {
	Write( ArgC, ArgV );
    }
  else if (strcasecmp( Operation, "read" ) == 0)
    {
	Read( BDMHandle, ArgC, ArgV );
    }
  else if (strcasecmp( Operation, "probe" ) == 0)
    {
	Probe( ArgC, ArgV );
    }
  else if (strcasecmp( Operation, "detect" ) == 0)
    {
	Detect( ArgC, ArgV );
    }
  else
    Usage( ArgV[0] );

  bdm_release( BDMHandle );

  return (EXIT_SUCCESS);
}
Beispiel #18
0
bool WhiteRectDetector::Detect(const BitMatrix& image, ResultPoint& p0, ResultPoint& p1, ResultPoint& p2, ResultPoint& p3)
{
	return Detect(image, INIT_SIZE, image.width() / 2, image.height() / 2, p0, p1, p2, p3);
}
Beispiel #19
0
void preProcess(IplImage *prv,IplImage *cur,IplImage *nxt,IplImage *wrt)
{    

	switch ( whichKernel)
	{
	case 0:{
		// diff two img
		//eabcdm();
		//f();
		cvSub(cur,prv,wrt);
		//_asm{
		//	push 0;
		//	mov eax, wrt;
		//	push eax;
		//	mov eax, prv;
		//	push eax;
		//	mov eax,cur;
		//	push eax;
		//	call cvSub;
		//	add  esp,10h
		//}
		break;
		   }
	case 1:
		Detect(wrt, cur,Robert);
		break;
	case 2:
		Detect(wrt, cur,Prewitt);
		break;
	case 3:
		Detect(wrt, cur,LapLas);
		break;
	case 4:
		histogramNormalize(wrt, cur);
		break;
	case 5:
		histogramNormalize(pImagePool[0], cur);
		Detect(wrt,pImagePool[0],Prewitt);
		break;
	case 6:
		{
			imgDFT(wrt, cur);
		}
		break;
	case 7:
		{
			Detect(wrt, cur,FreiChen);
			break;
		}
	case 8:
		{
			Filter(wrt, cur);
			break;
		}
	case 9:
		{

			transRGB2Gray( pImagePool[0], cur);
			Filter(wrt, pImagePool[0],averageFilter);

		}
	default:
		break;
	}

}
Beispiel #20
0
bool CScroll::EventProcess(const Event &event)
{
    CControl::EventProcess(event);

    if (m_buttonUp != nullptr && !m_bCapture)
    {
        if ( !m_buttonUp->EventProcess(event) )  return false;
    }
    if (m_buttonDown != nullptr && !m_bCapture)
    {
        if ( !m_buttonDown->EventProcess(event) )  return false;
    }

    if (m_buttonUp != nullptr && event.type == m_buttonUp->GetEventType() && m_step > 0.0f )
    {
        m_visibleValue -= m_step;
        if ( m_visibleValue < 0.0f )  m_visibleValue = 0.0f;
        AdjustGlint();

        m_event->AddEvent(Event(m_eventType));
    }

    if (m_buttonDown != nullptr && event.type == m_buttonDown->GetEventType() && m_step > 0.0f )
    {
        m_visibleValue += m_step;
        if ( m_visibleValue > 1.0f )  m_visibleValue = 1.0f;
        AdjustGlint();

        m_event->AddEvent(Event(m_eventType));
    }

    float hButton = (m_buttonUp != nullptr) ? (m_dim.x/0.75f) : 0.0f;

    if (event.type == EVENT_MOUSE_BUTTON_DOWN &&
        event.GetData<MouseButtonEventData>()->button == MOUSE_BUTTON_LEFT &&
        (m_state & STATE_VISIBLE)        &&
        (m_state & STATE_ENABLE)         )
    {
        if ( CControl::Detect(event.mousePos) )
        {
            Math::Point pos, dim;

            pos.y = m_pos.y+hButton;
            dim.y = m_dim.y-hButton*2.0f;
            pos.y += dim.y*(1.0f-m_visibleRatio)*(1.0f-m_visibleValue);
            dim.y *= m_visibleRatio;
            if ( event.mousePos.y < pos.y       ||
                 event.mousePos.y > pos.y+dim.y )  // click outside cabin?
            {
                float h = (m_dim.y-hButton*2.0f)*(1.0f-m_visibleRatio);
                float value = 1.0f-(event.mousePos.y-(m_pos.y+hButton+dim.y*0.5f))/h;
                if ( value < 0.0f )  value = 0.0f;
                if ( value > 1.0f )  value = 1.0f;
                m_visibleValue = value;
                AdjustGlint();

                m_event->AddEvent(Event(m_eventType));
            }
            m_bCapture = true;
            m_pressPos = event.mousePos;
            m_pressValue = m_visibleValue;
        }
    }

    if ( event.type == EVENT_MOUSE_MOVE && m_bCapture )
    {
        float h = (m_dim.y-hButton*2.0f)*(1.0f-m_visibleRatio);
        if ( h != 0 )
        {
            float value = m_pressValue - (event.mousePos.y-m_pressPos.y)/h;
            if ( value < 0.0f )  value = 0.0f;
            if ( value > 1.0f )  value = 1.0f;

            if ( value != m_visibleValue )
            {
                m_visibleValue = value;
                AdjustGlint();

                m_event->AddEvent(Event(m_eventType));
            }
        }
    }

    if (event.type == EVENT_MOUSE_BUTTON_UP &&
        event.GetData<MouseButtonEventData>()->button == MOUSE_BUTTON_LEFT &&
        m_bCapture)
    {
        m_bCapture = false;
    }

    if (event.type == EVENT_MOUSE_WHEEL &&
        Detect(event.mousePos))
    {
        auto data = event.GetData<MouseWheelEventData>();
        if (data->y > 0)
        {
            if (m_buttonUp != nullptr)
            {
                for (int i = 0; i < data->y; i++)
                    m_event->AddEvent(Event(m_buttonUp->GetEventType()));
            }
        }
        else
        {
            if (m_buttonDown != nullptr)
            {
                for (int i = 0; i < -(data->y); i++)
                    m_event->AddEvent(Event(m_buttonDown->GetEventType()));
            }
        }
        return false;
    }

    return true;
}
Beispiel #21
0
bool File::Assert(wstring& path, FileFormat format)
{
    return Detect(path) == format;
}
Beispiel #22
0
bool CEditValue::EventProcess(const Event &event)
{
    CControl::EventProcess(event);

    if ( (m_state & STATE_VISIBLE) == 0 )  return true;
    if ( (m_state & STATE_ENABLE) == 0 )  return true;
    if ( m_state & STATE_DEAD )  return true;

    if (m_edit != nullptr)
    {
        if ( m_edit->GetFocus()           &&
             event.type == EVENT_KEY_DOWN &&
             event.GetData<KeyEventData>()->key == KEY(RETURN)     )
        {
            float value = GetValue();
            if ( value > m_maxValue )  value = m_maxValue;
            if ( value < m_minValue )  value = m_minValue;
            SetValue(value, true);
            HiliteValue(event);
        }
        if ( !m_edit->EventProcess(event) )  return false;

        if ( event.type == m_edit->GetEventType() )
        {
            m_event->AddEvent(Event(m_eventType));
        }
    }

    if (m_buttonUp != nullptr)
    {
        if ( event.type == m_buttonUp->GetEventType() )
        {
            float value = GetValue()+m_stepValue;
            if ( value > m_maxValue )  value = m_maxValue;
            SetValue(value, true);
            HiliteValue(event);
        }
        if ( !m_buttonUp->EventProcess(event) )  return false;
    }

    if (m_buttonDown != nullptr)
    {
        if ( event.type == m_buttonDown->GetEventType() )
        {
            float value = GetValue()-m_stepValue;
            if ( value < m_minValue )  value = m_minValue;
            SetValue(value, true);
            HiliteValue(event);
        }
        if ( !m_buttonDown->EventProcess(event) )  return false;
    }

    if (event.type == EVENT_MOUSE_WHEEL &&
        Detect(event.mousePos))
    {
        float value = GetValue() + (m_stepValue * event.GetData<MouseWheelEventData>()->y);
        if ( value < m_minValue )  value = m_minValue;
        if ( value > m_maxValue )  value = m_maxValue;
        SetValue(value, true);
        HiliteValue(event);
    }

    return true;
}
Beispiel #23
0
bool CEditValue::EventProcess(const Event &event)
{
    float   value;

    CControl::EventProcess(event);

    if ( (m_state & STATE_VISIBLE) == 0 )  return true;
    if ( (m_state & STATE_ENABLE) == 0 )  return true;

    if ( m_edit != 0 )
    {
        if ( m_edit->GetFocus()           &&
             event.type == EVENT_KEY_DOWN &&
             event.key.key == KEY(RETURN)     )
        {
            value = GetValue();
            if ( value > m_maxValue )  value = m_maxValue;
            if ( value < m_minValue )  value = m_minValue;
            SetValue(value, true);
            HiliteValue(event);
        }
        if ( !m_edit->EventProcess(event) )  return false;

        if ( event.type == m_edit->GetEventType() )
        {
            Event       newEvent(m_eventType);
            m_event->AddEvent(newEvent);
        }
    }

    if ( m_buttonUp != 0 )
    {
        if ( event.type == m_buttonUp->GetEventType() )
        {
            value = GetValue()+m_stepValue;
            if ( value > m_maxValue )  value = m_maxValue;
            SetValue(value, true);
            HiliteValue(event);
        }
        if ( !m_buttonUp->EventProcess(event) )  return false;
    }

    if ( m_buttonDown != 0 )
    {
        if ( event.type == m_buttonDown->GetEventType() )
        {
            value = GetValue()-m_stepValue;
            if ( value < m_minValue )  value = m_minValue;
            SetValue(value, true);
            HiliteValue(event);
        }
        if ( !m_buttonDown->EventProcess(event) )  return false;
    }

    if (event.type == EVENT_MOUSE_WHEEL &&
        event.mouseWheel.dir == WHEEL_UP &&
        Detect(event.mousePos))
    {
        value = GetValue()+m_stepValue;
        if ( value > m_maxValue )  value = m_maxValue;
        SetValue(value, true);
        HiliteValue(event);
    }
    if ( event.type == EVENT_KEY_DOWN &&
         event.mouseWheel.dir == WHEEL_DOWN &&
         Detect(event.mousePos))
    {
        value = GetValue()-m_stepValue;
        if ( value < m_minValue )  value = m_minValue;
        SetValue(value, true);
        HiliteValue(event);
    }

    return true;
}
Beispiel #24
0
void DetectFaces(          // all face rects into detpars
    vec_DetPar&  detpars,  // out
    const Image& img,      // in
    int          minwidth) // in: as percent of img width
{   

    //Polyphemus version: we already have the face, returns the whole image rectangle
    bool changedForPolyphemus = true;

    //UO
    //CV_Assert(!facedet_g.empty()); // check that OpenFaceDetector_ was called
    //OU

    if(changedForPolyphemus)
    {
        /*
        #ifdef WITH_GUI
        cv::namedWindow("StasmFace", CV_WINDOW_NORMAL);
        cv::imshow("StasmFace", img);//cv::Mat(img, Rect(0,0,img.cols, img.rows)));
        #endif
        */

        //if (img.cols != 800 || img.rows != 600) // sanity check
        //Err("Image must be 800x600 (your image is %dx%d)", img.cols, img.rows);
        DetPar detpar;
        detpar.x = img.cols / 2.; // approximate center of face
        detpar.y = img.rows / 2.;
        detpar.width = img.cols; // approximate size of face
        detpar.height = img.rows;
        detpar.yaw = 0;
        detpar.eyaw = EYAW00;
        detpars.resize(1);
        detpars[0] = detpar;

        //minwidth = 40;
    }
    else
    {

        int leftborder = 0, topborder = 0; // border size in pixels
        Image bordered_img(BORDER_FRAC == 0?
                           img: EnborderImg(leftborder, topborder, img));

        // Detection results are very slightly better with equalization
        // (tested on the MUCT images, which are not pre-equalized), and
        // it's quick enough to equalize (roughly 10ms on a 1.6 GHz laptop).

        Image equalized_img; cv::equalizeHist(bordered_img, equalized_img);

        CV_Assert(minwidth >= 1 && minwidth <= 100);

        // TODO smallest bioid faces are about 80 pixels width, hence 70 below
        const int minpix =
            MAX(minwidth <= 5? 70: 100, cvRound(img.cols * minwidth / 100.));

        // the params below are accurate but slow
        static const double SCALE_FACTOR   = 1.1;
        static const int    MIN_NEIGHBORS  = 3;
        static const int    DETECTOR_FLAGS = 0;

        vec_Rect facerects = // all face rects in image
            Detect(equalized_img, facedet_g, NULL,
                   SCALE_FACTOR, MIN_NEIGHBORS, DETECTOR_FLAGS, minpix);

        // copy face rects into the detpars vector
        detpars.resize(NSIZE(facerects));
        for (int i = 0; i < NSIZE(facerects); i++)
        {
            Rect* facerect = &facerects[i];
            DetPar detpar; // detpar constructor sets all fields INVALID
            // detpar.x and detpar.y is the center of the face rectangle
            detpar.x = facerect->x + facerect->width / 2.;
            detpar.y = facerect->y + facerect->height / 2.;
            detpar.x -= leftborder; // discount the border we added earlier
            detpar.y -= topborder;
            detpar.width  = double(facerect->width);
            detpar.height = double(facerect->height);
            detpar.yaw = 0; // assume face has no yaw in this version of Stasm
            detpar.eyaw = EYAW00;
            detpars[i] = detpar;
        }
    }

}
Beispiel #25
0
void main (int argc, char *argv[])
 {
   cout << "Squirrel 1.16/release, Adaptive answer Service for USR Voice modems" << endl;
   cout << "Copyright (c)2000 Eugeniy Gryaznov, Compiled on 02.05.00 at 21:09" << endl;
   if(argc<2) {
      cout << " Use <squirrel.exe> <action> [<action param>] [switches]" << endl;
      cout << "  action:   PLAY,REC,MAILER,MAIN" << endl;
      cout << "      PLAY f.gsm     Play file to speaker(modem)" << endl;
      cout << "      REC f.gsm      Record from microphone(modem) to file" << endl;
      cout << "      MAILER         Mailer compatible mode" << endl;
      cout << "      MAIN           Run in master mode" << endl;
      cout << "      CONV f.gsm     Convert GSM ->WAV" << endl;
      cout << "  switches: [/L] [/D] [/P]" << endl;
      cout << "      /L             switch Playing/Recording device" << endl;
      cout << "      /D             switch Show debug info" << endl;
      cout << "      /P             switch close/real_close port" << endl;
      cout << "      /B             switch 8/16 bit wave output" << endl;
      cout << " Ex: squirrel play allo.gsm /L /D" << endl;
      cout << "     squirrel main" << endl;
      ErrorExit(0,"Help screen");
   }

   // Get default CTL name
   char ctl[128];
   char *ext = "CTL";
   strcpy(ctl,argv[0]);
   strcpy(ctl+strlen(ctl)-3,ext);
   SetDefault();

   // Check ARGV
   int Task = 0, swch = 0; // 1 - PLAY, 2 - REC, 3 - MAILER, 4 - MAIN
   char TParam[128],fname[128],*outw;
   int postdo = 0;

   // Get task type
   if (strcmp(strupr(argv[1]),"PLAY")==0) { strcpy(TParam,argv[2]);Task=1; }
   else if (strcmp(strupr(argv[1]),"REC")==0) { strcpy(TParam,argv[2]);Task=2; }
   else if (strcmp(strupr(argv[1]),"MAILER")==0) { strcpy(TParam,argv[2]);Task=3; }
   else if (strcmp(strupr(argv[1]),"MAIN")==0) { strcpy(TParam,argv[2]);Task=4; }
   else if (strcmp(strupr(argv[1]),"CONV")==0) { strcpy(TParam,argv[2]);Task=5; }
   else ErrorExit(1,"Unknown action");
   if ((Task==1||Task==2||Task==5)&&argc==2) ErrorExit(1,"not enough params");

   // Process switches
   for (int argnum=2;argnum<argc;argnum++){
      if ((Task!=1&&Task!=2&&Task!=5)||argnum!=2){
        if (strcmp(strupr(argv[argnum]),"/D")==0) swch|=1;
        else if (strcmp(strupr(argv[argnum]),"/L")==0) swch|=2;
        else if (strcmp(strupr(argv[argnum]),"/P")==0) swch|=4;
        else if (strcmp(strupr(argv[argnum]),"/B")==0) swch|=8;
        else ErrorExit(1,"Unknown switch");
      }
   }

   cout << "TASK: ";
   switch(Task){
     case 1: cout << "playing file (device <- " << TParam << ")" << endl;break;
     case 2: cout << "recording file (device -> " << TParam << ")" << endl;break;
     case 3: cout << "mailer mode" << endl;break;
     case 4: cout << "master mode" << endl;break;
   }

   if (Task<5){

     // Read config + FIX switches
     ReadConfig(ctl);
     if (swch&1) cfg.debuginfo=(cfg.debuginfo+1)%2;
     if (swch&2) cfg.pln=(cfg.pln+1)%2;
     if (swch&4) cfg.realcl=(cfg.realcl+1)%2;
     if (swch&8) cfg.wav8bit=(cfg.wav8bit+1)%2;

     // Open COMPort
     OpenComm(cfg.baud,cfg.ioport,cfg.irq);
     if(prtst!=-1) ErrorExit(3,"Communication port not found");

     // Init screen
     StartupScr();

     // Init modem
     SendModemStr(&cfg.init,"Initializing modem");
     SendModemStr(&cfg.voice,"Voice mode");
   }

   // Start Log
   if (Task==3||Task==4){
      struct time _t;
      struct date _d;
      gettime(&_t);getdate(&_d);

      write_log("\n -- executed on ");
      write_log_num(_d.da_day);write_log(".");
      write_log_num(_d.da_mon);write_log(".");
      write_log_num(_d.da_year);write_log(" at ");
      write_log_num(_t.ti_hour);write_log(":");
      write_log_num(_t.ti_min);write_log(" --\n");
   }

   // Main work
   switch(Task){

     case 1:
       PlayFile(TParam);
       break;

     case 2:
       cfg.wavout=0;
       RecFile(TParam,0);
       break;

     case 3:

       if (!cfg.gsmframe) ErrorExit(78,"mailer mode require USE_GSM=1");
       cfg.up=0;cfg.pln=0;
       if (cfg.useaon&1){
         AON();
       } else {
         if (cfg.hook){
           SendModemStr(&cfg.offhook,"Offhook");
           delay(cfg.wallo);
         }
       }
       PlayFile(cfg.sallo);
       if (cfg.loglev&2) write_log("detecting\n");
       switch (Detect()){

         case 1: // Modem
            CreateFlag(cfg.ata);
            SendModemStr(&cfg.data,"Data mode");
            SendModemStr(&cfg.mailinit,"Initializing modem to connect");
            write_log("Detected: MODEM\n");
            ErrorExit(0,"modem detected");
            break;

         case 2: // Voice
            write_log("Detected: VOICE\n");
            PlayFile(cfg.swait);
            for (int curring=0;curring<cfg.RTL;curring++){
               if (!kbhit()){
                if (strlen(cfg.soundfl))
                   CreateFlag(cfg.soundfl);
                else sound(cfg.khz);
                SendModemStr(&cfg.beep,"Beep");
                nosound();
               }
               if (kbhit()) break;
               if (curring+1!=cfg.RTL) delay(cfg.delayring);
            }
            ch=0;while (kbhit()) ch=getch();
            if (cfg.auto_detect&&ch!=27&&ch!=32){
              // check if voice present

              cout << " ! auto : speach in line" << endl;FixLine();
              if (cfg.loglev&2) write_log("detecting\n");
              ch=0;cfg.limit=cfg.auto_detect;
              if ((ch=Detect())==2) ch=32;
              if (ch==3||ch==4) break;
            }
            if (ch!=27) if (ch==32){
              cout << " ! autoanswer skipped" << endl;FixLine();
              write_log("autoanswer skipped\n");
              postdo=1;
            } else {
              PlayFile(cfg.sauto);
              SendModemStr(&cfg.abeep,"aBeep");
              generate_name(fname);
              write_log("Recording: ");write_log(fname);write_log("\n");
              RecFile(fname,cfg.rec_time);
            }
            break;
         case 3:
            write_log("Detected: BUSY\n");break;
         case 4:
            write_log("Detected: DIAL TONE\n");break;
       }
       SendModemStr(&cfg.onhook,"Onhook");
       break;

     case 4:
       int wring;
       char rng[100];cfg.up=0;cfg.pln=0;
       while(kbhit()) getch();

       if (cfg.gsmframe==0&&cfg.useaon!=0) ErrorExit(73,"AON require USE_GSM=1");
       while(!kbhit()){
         cout << "  Waiting for RING ...";rng[0]=0;
         while(!kbhit()&&strstr(rng,"RING")==NULL){
           while(ReadComm(ch)){
             rng[strlen(rng)+1]=0;
             rng[strlen(rng)]=ch;
             if (strlen(rng)==95) rng[0]=0;
           }
         }

         if (!kbhit()){
           cout << endl;FixLine();
           cout << " ! RING .";
           for(wring=0;wring<(cfg.ring-1);wring++){
             if (!WaitFor("RING",7,cfg.debuginfo))
               { cout << " <no more rings>" << endl;FixLine();wring=0;break;}
             else
               cout << ".";
           }

         }
         if (!kbhit()&&wring){

           // Wait cfg.ring

           cout << endl;FixLine();

           if (cfg.useaon&2){
             AON();
           } else {
             SendModemStr(&cfg.offhook,"Offhook");
             delay(cfg.wallo);
           }
           cfg.up=0;
           PlayFile(cfg.sauto);
           SendModemStr(&cfg.abeep,"aBeep");
           generate_name(fname);
           RecFile(fname,cfg.rec_time);
           SendModemStr(&cfg.onhook,"Onhook");
           SendModemStr(&cfg.init,"Initializing modem");
           SendModemStr(&cfg.voice,"Voice mode");
           while(kbhit()) getch();
         }
       }
       cout << endl;FixLine();
       while(kbhit()) getch();
       break;

     case 5:

       // Open files
       if (swch&8) cfg.wav8bit=(cfg.wav8bit+1)%2;
       fp=fopen(TParam,"rb");
       if (fp==NULL) ErrorExit(93,"error: .gsm input");
       outw=TParam;
       cout << "GSM->WAV converting: " << TParam << " -> ";
       while (strchr(outw,'\\')!=NULL) outw=strchr(outw,'\\');
       while (strchr(outw,'/')!=NULL) outw=strchr(outw,'/');
       if (strlen(outw)==0) ErrorExit(153,"out name error");
       if (strchr(outw,'.')!=NULL) *strchr(outw,'.')=0;
       strcat(strlwr(TParam),".wav");
       cout << TParam;if(cfg.wav8bit) cout << " (8bit)";cout << endl;
       if (!Start_GSM_WAV(TParam,cfg.wav8bit)){ cout << "output file error";exit(1);}

       while (fread(gsmb,1,33,fp)==33){
          decode_block(gsmb,cfg.wav8bit);
       }

       // close file
       fclose(fp);
       Close_GSM_WAV();
       ErrorExit(0,"OK");

   }

   // Deinit
   SendModemStr(&cfg.data,"Data mode");
   SendModemStr(&cfg.deinit,"Deinitializing modem");

   if (postdo&&cfg.postspace){
     cout << " ! Press any key to return to Mailer";
     getch();sound(440);delay(5);nosound();
     cout << endl;FixLine();
   }

   // Close COMPort & Exit
   ErrorExit(0,"All ok");

 }
Beispiel #26
0
bool InputIsoFile::Open( const wxString& srcfile, bool testOnly )
{
	Close();
	m_filename = srcfile;
	m_reader = NULL;

	bool isBlockdump = false;
	bool isCompressed = false;

	// First try using a compressed reader.  If it works, go with it.
	m_reader = CompressedFileReader::GetNewReader(m_filename);
	isCompressed = m_reader != NULL;

	// If it wasn't compressed, let's open it has a FlatFileReader. 
	if (!isCompressed)
	{
		// Allow write sharing of the iso based on the ini settings.
		// Mostly useful for romhacking, where the disc is frequently
		// changed and the emulator would block modifications
		m_reader = new FlatFileReader(EmuConfig.CdvdShareWrite);
	}

	m_reader->Open(m_filename);

	// It might actually be a blockdump file.
	// Check that before continuing with the FlatFileReader.
	isBlockdump = BlockdumpFileReader::DetectBlockdump(m_reader);
	if (isBlockdump)
	{
		delete m_reader;

		BlockdumpFileReader *bdr = new BlockdumpFileReader();
		bdr->Open(m_filename);

		m_blockofs = bdr->GetBlockOffset();
		m_blocksize = bdr->GetBlockSize();

		m_reader = bdr;

		ReadUnit = 1;
	}

	bool detected = Detect();
		
	if(testOnly)
		return detected;
		
	if (!detected)
		throw Exception::BadStream()
			.SetUserMsg(_("Unrecognized ISO image file format"))
			.SetDiagMsg(L"ISO mounting failed: PCSX2 is unable to identify the ISO image type.");

	if(!isBlockdump && !isCompressed)
	{
		ReadUnit = MaxReadUnit;
		
		m_reader->SetDataOffset(m_offset);
		m_reader->SetBlockSize(m_blocksize);

		// Returns the original reader if single-part or a Multipart reader otherwise
		AsyncFileReader* m_reader_old = m_reader;
		m_reader =	MultipartFileReader::DetectMultipart(m_reader);
		if (m_reader != m_reader_old) // Not the same object the old one need to be deleted
			delete m_reader_old;
	}

	m_blocks = m_reader->GetBlockCount();

	Console.WriteLn(Color_StrongBlue, L"isoFile open ok: %s", WX_STR(m_filename));

	ConsoleIndentScope indent;

	Console.WriteLn("Image type  = %s", nameFromType(m_type)); 
	//Console.WriteLn("Fileparts   = %u", m_numparts); // Pointless print, it's 1 unless it says otherwise above
	DevCon.WriteLn ("blocks      = %u", m_blocks);
	DevCon.WriteLn ("offset      = %d", m_offset);
	DevCon.WriteLn ("blocksize   = %u", m_blocksize);
	DevCon.WriteLn ("blockoffset = %d", m_blockofs);

	return true;
}
Beispiel #27
0
static TmEcode FlowWorker(ThreadVars *tv, Packet *p, void *data, PacketQueue *preq, PacketQueue *unused)
{
    FlowWorkerThreadData *fw = data;
    void *detect_thread = SC_ATOMIC_GET(fw->detect_thread);

    SCLogDebug("packet %"PRIu64, p->pcap_cnt);

    /* update time */
    if (!(PKT_IS_PSEUDOPKT(p))) {
        TimeSetByThread(tv->id, &p->ts);
    }

    /* handle Flow */
    if (p->flags & PKT_WANTS_FLOW) {
        FLOWWORKER_PROFILING_START(p, PROFILE_FLOWWORKER_FLOW);

        FlowHandlePacket(tv, fw->dtv, p);
        if (likely(p->flow != NULL)) {
            DEBUG_ASSERT_FLOW_LOCKED(p->flow);
            if (FlowUpdate(p) == TM_ECODE_DONE) {
                FLOWLOCK_UNLOCK(p->flow);
                return TM_ECODE_OK;
            }
        }
        /* Flow is now LOCKED */

        FLOWWORKER_PROFILING_END(p, PROFILE_FLOWWORKER_FLOW);

    /* if PKT_WANTS_FLOW is not set, but PKT_HAS_FLOW is, then this is a
     * pseudo packet created by the flow manager. */
    } else if (p->flags & PKT_HAS_FLOW) {
        FLOWLOCK_WRLOCK(p->flow);
    }

    SCLogDebug("packet %"PRIu64" has flow? %s", p->pcap_cnt, p->flow ? "yes" : "no");

    /* handle TCP and app layer */
    if (p->flow && PKT_IS_TCP(p)) {
        SCLogDebug("packet %"PRIu64" is TCP. Direction %s", p->pcap_cnt, PKT_IS_TOSERVER(p) ? "TOSERVER" : "TOCLIENT");
        DEBUG_ASSERT_FLOW_LOCKED(p->flow);

        /* if detect is disabled, we need to apply file flags to the flow
         * here on the first packet. */
        if (detect_thread == NULL &&
                ((PKT_IS_TOSERVER(p) && (p->flowflags & FLOW_PKT_TOSERVER_FIRST)) ||
                 (PKT_IS_TOCLIENT(p) && (p->flowflags & FLOW_PKT_TOCLIENT_FIRST))))
        {
            DisableDetectFlowFileFlags(p->flow);
        }

        FLOWWORKER_PROFILING_START(p, PROFILE_FLOWWORKER_STREAM);
        StreamTcp(tv, p, fw->stream_thread, &fw->pq, NULL);
        FLOWWORKER_PROFILING_END(p, PROFILE_FLOWWORKER_STREAM);

        if (FlowChangeProto(p->flow)) {
            StreamTcpDetectLogFlush(tv, fw->stream_thread, p->flow, p, &fw->pq);
        }

        /* Packets here can safely access p->flow as it's locked */
        SCLogDebug("packet %"PRIu64": extra packets %u", p->pcap_cnt, fw->pq.len);
        Packet *x;
        while ((x = PacketDequeue(&fw->pq))) {
            SCLogDebug("packet %"PRIu64" extra packet %p", p->pcap_cnt, x);

            // TODO do we need to call StreamTcp on these pseudo packets or not?
            //StreamTcp(tv, x, fw->stream_thread, &fw->pq, NULL);
            if (detect_thread != NULL) {
                FLOWWORKER_PROFILING_START(x, PROFILE_FLOWWORKER_DETECT);
                Detect(tv, x, detect_thread, NULL, NULL);
                FLOWWORKER_PROFILING_END(x, PROFILE_FLOWWORKER_DETECT);
            }

            //  Outputs
            OutputLoggerLog(tv, x, fw->output_thread);

            /* put these packets in the preq queue so that they are
             * by the other thread modules before packet 'p'. */
            PacketEnqueue(preq, x);
        }

    /* handle the app layer part of the UDP packet payload */
    } else if (p->flow && p->proto == IPPROTO_UDP) {
        FLOWWORKER_PROFILING_START(p, PROFILE_FLOWWORKER_APPLAYERUDP);
        AppLayerHandleUdp(tv, fw->stream_thread->ra_ctx->app_tctx, p, p->flow);
        FLOWWORKER_PROFILING_END(p, PROFILE_FLOWWORKER_APPLAYERUDP);
    }

    /* handle Detect */
    DEBUG_ASSERT_FLOW_LOCKED(p->flow);
    SCLogDebug("packet %"PRIu64" calling Detect", p->pcap_cnt);

    if (detect_thread != NULL) {
        FLOWWORKER_PROFILING_START(p, PROFILE_FLOWWORKER_DETECT);
        Detect(tv, p, detect_thread, NULL, NULL);
        FLOWWORKER_PROFILING_END(p, PROFILE_FLOWWORKER_DETECT);
    }

    // Outputs.
    OutputLoggerLog(tv, p, fw->output_thread);

    /*  Release tcp segments. Done here after alerting can use them. */
    if (p->flow != NULL && p->proto == IPPROTO_TCP) {
        FLOWWORKER_PROFILING_START(p, PROFILE_FLOWWORKER_TCPPRUNE);
        StreamTcpPruneSession(p->flow, p->flowflags & FLOW_PKT_TOSERVER ?
                STREAM_TOSERVER : STREAM_TOCLIENT);
        FLOWWORKER_PROFILING_END(p, PROFILE_FLOWWORKER_TCPPRUNE);
    }

    if (p->flow) {
        DEBUG_ASSERT_FLOW_LOCKED(p->flow);
        FLOWLOCK_UNLOCK(p->flow);
    }

    return TM_ECODE_OK;
}
Beispiel #28
0
/// <summary>
/// Handle new body data
/// <param name="nTime">timestamp of frame</param>
/// <param name="nBodyCount">body data count</param>
/// <param name="ppBodies">body data in frame</param>
/// </summary>
void CColorBasics::ProcessBody(INT64 nTime, int nBodyCount, IBody** ppBodies)
{
	if (m_hWnd)
	{
		HRESULT hr = S_OK;

		D2D1_POINT_2F start;
		start.x = 1500.0;
		start.y = 800.0;

		D2D1_POINT_2F quit;
		quit.x = 300.0;
		quit.y = 800.0;

		//int width = 0;
		//int height = 0;
		if (SUCCEEDED(hr) && m_pCoordinateMapper)
		{
			// 先に実行しているProcessColor()にて行っているのでコメント
			//hr = m_pDrawColor->BeginDraw();

			DetectionResult nEngaged[6] = { DetectionResult_Unknown };
			PointF lean;

			//RECT rct;
			//GetClientRect(GetDlgItem(m_hWnd, IDC_VIDEOVIEW), &rct);
			//width = rct.right;
			//height = rct.bottom;

			UINT64 nTrackBody = 10;

			for (int i = 0; i < nBodyCount; ++i)
			{
				IBody* pBody = ppBodies[i];
				if (pBody)
				{
					// 手旗二人での対戦モードを想定してインデックスを取得する。
					// 本来はゲーム前に対戦の二人wフィックスしておくべきだろうが。
					// 
					// トラッキングされているボディかはちゃんと確かめること。
					BOOLEAN bTracked = false;
					hr = pBody->get_IsTracked(&bTracked);

					// Engaged()は使えるみたい。これは、視野に入ってきた人を認識するものだろう。
					hr = pBody->get_Engaged(&nEngaged[i]);
					pBody->get_Lean(&lean);
					// 以下はまだ使えないようだ
					//hr = pBody->GetAppearanceDetectionResults((UINT)i, &nEngaged[i]);

					if (SUCCEEDED(hr) && bTracked)
					{
						// トラッキングが無効な場合のインデックスは0が返るので使い方に注意!!
						UINT64 nBodyIndex = 0;
						hr = pBody->get_TrackingId(&nBodyIndex);

						Joint joints[JointType_Count];
						D2D1_POINT_2F jointPoints[JointType_Count];
						HandState leftHandState = HandState_Unknown;
						HandState rightHandState = HandState_Unknown;

						pBody->get_HandLeftState(&leftHandState);
						pBody->get_HandRightState(&rightHandState);

						hr = pBody->GetJoints(_countof(joints), joints);
						if (SUCCEEDED(hr))
						{
							// スクリーン座標に変換
							for (int j = 0; j < _countof(joints); ++j)
							{
								jointPoints[j] = BodyToScreen(joints[j].Position);
							}
							// ここに頭部に丸を描いて、ボディ番号を表示
							m_pDrawColor->DrawHead(jointPoints[JointType_Head], i, nEngaged[i], lean);

							// 手先がある領域にきたら実行
							// ボタンのような
							// 現状、複数人が認識されても実行するので、本来は最初に認識された一人のみにする必要がある。
							float xy[2] = { 0.0 };

							if (!m_bSemaphore)
							{
								if (m_pSemaphore[0])
								{
									delete m_pSemaphore[0];
									m_pSemaphore[0] = NULL;
								}
								if (m_pSemaphore[1])
								{
									delete m_pSemaphore[1];
									m_pSemaphore[1] = NULL;
								}
								m_nButton = 1;
								xy[0] = jointPoints[JointType_HandTipRight].x - start.x;
								xy[1] = jointPoints[JointType_HandTipRight].y - start.y;
								if (sqrt( xy[0]*xy[0] + xy[1]*xy[1] ) < 100.0 )
								{
									if (nTrackBody == 10 || nTrackBody == nBodyIndex)
									{
										m_nButton = 0;
										nTrackBody = nBodyIndex;
									}
								}
							}
							else
							{
								// 手旗スタート
								// 手旗判定
								if (m_pSemaphore[0] == NULL)
								{
									m_pSemaphore[0] = new Semaphore( &nBodyIndex );
								}
								else
								{
									if (m_pSemaphore[1] == NULL && !m_pSemaphore[0]->ItsMe(&nBodyIndex))
									{
										m_pSemaphore[1] = new Semaphore(&nBodyIndex);
									}
								}

								// カウント
								// 基本ポーズでのデータ取得
								// 手旗本番処理
								// 手旗の判定に画像と同等のフレームは必要はないのでは。
								// タイマーでBodyフレームを取得し、それで手旗判定を行う。
								if (m_pSemaphore[0])
								{
									m_pSemaphore[0]->SetSignalType(&nBodyIndex, jointPoints, m_pDrawColor);
								}
								if (m_pSemaphore[1])
								{
									m_pSemaphore[1]->SetSignalType(&nBodyIndex, jointPoints, m_pDrawColor);
								}
								//m_pSemaphore[0]->Practice(nTime, jointPoints, m_pDrawColor);

								// quitボタン処理
								m_nButton = 2;
								// 基本ポーズ用の表示
								xy[0] = jointPoints[JointType_HandTipLeft].x - quit.x;
								xy[1] = jointPoints[JointType_HandTipLeft].y - quit.y;
								if (sqrt( xy[0]*xy[0] + xy[1]*xy[1] ) < 100.0 )
								{
									if (nTrackBody == 10 || nTrackBody == nBodyIndex)
									{
										m_nButton = 0;
										nTrackBody = nBodyIndex;
									}
								}
							}
							m_pDrawColor->DrawBody(joints, jointPoints);
							//m_pDrawColor->DrawHand(leftHandState, jointPoints[JointType_HandLeft]);
							//m_pDrawColor->DrawHand(rightHandState, jointPoints[JointType_HandRight]);

							Detect(pBody);
							//break;
						}
					}
				}
			}
			if (!m_bSemaphore)
			{
				// このボタン処理でウィンドウにメッセージを送っている
				m_pDrawColor->DrawButton(start, m_nButton);
			}
			else
			{
				m_pDrawColor->DrawButton(quit, m_nButton);
			}
			// 二人対戦モードのお題表示
			if (Question(nTime))
			{
				m_pDrawColor->DrawButton(quit, 0);
			}

			m_pDrawColor->EndDraw();
		}
	}
}