예제 #1
0
//=============================================================================
int isWithinTri(double x,double y,cv::Mat &tri,cv::Mat &shape)
{
    int i,j,k,t,n = tri.rows,p = shape.rows/2;
    double s11,s12,s21,s22,s31,s32;
    for(t = 0; t < n; t++) {
        i = tri.it(t,0);
        j = tri.it(t,1);
        k = tri.it(t,2);
        s11 = shape.db(i  ,0);
        s21 = shape.db(j  ,0);
        s31 = shape.db(k  ,0);
        s12 = shape.db(i+p,0);
        s22 = shape.db(j+p,0);
        s32 = shape.db(k+p,0);
        if(sameSide(x,y,s11,s12,s21,s22,s31,s32) &&
                sameSide(x,y,s21,s22,s11,s12,s31,s32) &&
                sameSide(x,y,s31,s32,s11,s12,s21,s22))return t;
    }
    return -1;
}
예제 #2
0
bool
DetectorNCC::response(cv::Mat & im, cv::Mat & sh,
		      cv::Size wSize,
		      cv::Mat& visi)
{

  cv::Mat simTransfMat;
  CalcSimT(_refs, sh, simTransfMat);

  int n = sh.rows/2;
  cv::Mat shape = sh.reshape(0,2);

  prob_.resize(n);
  wmem_.resize(n);
  pmem_.resize(n);

#ifdef _OPENMP
#pragma omp parallel for
#endif
  for(int i=0; i<n; i++){
    if(visi.it(i,0) ==0) continue;
    int w = wSize.width + _patch[i]._w - 1; 
    int h = wSize.height + _patch[i]._h - 1;
    simTransfMat.rl(0,2) = shape.rl(0,i);
    simTransfMat.rl(1,2) = shape.rl(1,i);
 
    if((w>wmem_[i].cols) || (h>wmem_[i].rows))
      wmem_[i].create(h,nextMultipleOf4(w),CV_32F);
    
    cv::Mat wimg = wmem_[i](cv::Rect(0,0,w,h));
    CvMat wimg_o = wimg,sim_o = simTransfMat; IplImage im_o = im;
    cvGetQuadrangleSubPix(&im_o,&wimg_o,&sim_o);
    if(wSize.height > pmem_[i].rows)
      pmem_[i].create(wSize.height, nextMultipleOf4(wSize.width), CV_REAL);
    
    prob_[i] = pmem_[i](cv::Rect(cv::Point(0,0),wSize));
    _patch[i].Response(wimg,prob_[i]);
  }

  return true;
}