コード例 #1
0
ファイル: csk.cpp プロジェクト: foolwood/CSK
void GetSubWindow(const Mat &frame, Mat &subWindow, Point centraCoor, Size sz, Mat &cos_window){
  
  Point lefttop(cvFloor(centraCoor.x) - cvFloor(float(sz.width) / 2.0) + 1, cvFloor(centraCoor.y) - cvFloor(float(sz.height) / 2.0) + 1);
  Point rightbottom(cvFloor(centraCoor.x) - cvFloor(float(sz.width) / 2.0) + sz.width+1, cvFloor(centraCoor.y) - cvFloor(float(sz.height) / 2.0) + sz.height+1);
  Rect idea_rect(lefttop, rightbottom);
  Rect true_rect = idea_rect&Rect(0, 0, frame.cols, frame.rows);
  Rect border(0, 0, 0, 0);
  if (true_rect.area() == 0)
  {
    int x_start, x_width, y_start, y_height;
    
    x_start = min(frame.cols-1,max(0,idea_rect.x));
    x_width = max(1,min( idea_rect.x + idea_rect.width,frame.cols) - x_start);
    y_start = min(frame.rows - 1, max(0, idea_rect.y));
    y_height = max(1, min(idea_rect.y + idea_rect.height,frame.rows) - y_start);

    true_rect = Rect(x_start, y_start, x_width, y_height);
    
    if ((idea_rect.x + idea_rect.width - 1) < 0)
      border.x = sz.width - 1;
    else if (idea_rect.x > (frame.cols-1))
      border.width = sz.width - 1;
    else
    {
      if (idea_rect.x < 0)
        border.x = -idea_rect.x;
      if ((idea_rect.x + idea_rect.width) > frame.cols)
        border.width = idea_rect.x + idea_rect.width - frame.cols;
    }

    if ((idea_rect.y + idea_rect.height - 1) < 0)
      border.y = sz.height - 1;
    else if (idea_rect.y > (frame.rows - 1))
      border.height = sz.height - 1;
    else
    {
      if (idea_rect.y < 0)
        border.y = -idea_rect.y;
      if ((idea_rect.y + idea_rect.height) > frame.rows)
        border.height = idea_rect.y + idea_rect.height - frame.rows;
    }

    frame(true_rect).copyTo(subWindow);
  }
  else if (true_rect.area() == idea_rect.area())
  {
    frame(true_rect).copyTo(subWindow);
  }
  else
  {
    frame(true_rect).copyTo(subWindow);
    border.y = true_rect.y - idea_rect.y;
    border.height = idea_rect.y + idea_rect.height - true_rect.y - true_rect.height;
    border.x = true_rect.x - idea_rect.x;
    border.width = idea_rect.x + idea_rect.width - true_rect.x - true_rect.width;
  }

  if (border != Rect(0,0,0,0))
  {
    cv::copyMakeBorder(subWindow, subWindow, border.y, border.height, border.x, border.width, cv::BORDER_REPLICATE);
  }

  subWindow.convertTo(subWindow, CV_64FC1,1.0/255.0,-0.5);
  subWindow = subWindow.mul(cos_window);
}
コード例 #2
0
ファイル: CxImageCtrl.cpp プロジェクト: alex765022/IBN
void CCxImageCtrl::OnLButtonUp(UINT nFlags, CPoint point) 
{
	CPoint	imagePoint(point);
	
	ClientToImage(imagePoint);
	
	if(m_bCaptureWasSet&&m_hImage.IsInside(imagePoint.x,imagePoint.y))
	{
		CPoint lefttop(m_RefPoint), rightbottom(point);
		ClientToImage(lefttop);
		ClientToImage(rightbottom);

		switch(GetState()) 
		{
		case CCxImageCtrl::IS_Move:
			SetCursor(AfxGetApp()->LoadCursor(IDC_HANDCATCHCURSOR1));
			break;
		case CCxImageCtrl::IS_Crop:

			SaveImageToUndo();

			m_hImage.Crop(CRect(lefttop,rightbottom));

			//  [Tue 7/6/2004]
			//m_bCurrentImageWasSave = false;
			m_bIsSaved = false;

			Refresh();

			break;
		case CCxImageCtrl::IS_TextMove:
		case CCxImageCtrl::IS_Text:
			
			m_bIsSaved = false;

			break;
		case CCxImageCtrl::IS_Pen:
			CPoint	fromPoint(m_RefPoint), toPoint(point);
			
			ClientToImage(fromPoint);
			ClientToImage(toPoint);
			
			m_hImage.DrawLine(fromPoint.x, toPoint.x, m_hImage.GetHeight()-fromPoint.y,m_hImage.GetHeight()-toPoint.y,GetPenColor());

			//  [Tue 7/6/2004]
			//m_bCurrentImageWasSave = false;
			m_bIsSaved = false;

			break;		
		}
	}

	if(m_bCaptureWasSet)
	{
		ReleaseCapture();
		Invalidate(FALSE);
		m_bCaptureWasSet = FALSE;
	}
	
	
	CWnd::OnLButtonUp(nFlags, point);
}