Exemplo n.º 1
0
        LedMeasurement augmentKeypoint(cv::Mat grayImage,
                                       cv::KeyPoint origKeypoint) {
            // Saving this now before we monkey with m_floodFillMask
            cv::bitwise_not(m_floodFillMask, m_scratchNotMask);

            const int loDiff = 2;
            const int upDiff = 2;
            auto m_area = cv::floodFill(
                grayImage, m_floodFillMask, origKeypoint.pt, 255,
                &m_filledBounds, loDiff, upDiff,
                CV_FLOODFILL_MASK_ONLY | (/* connectivity 4 or 8 */ 4) |
                    (/* value to write in to mask */ 255 << 8));
            // Now m_floodFillMask contains the mask with both our point
            // and all other points so far. We need to split them by ANDing with
            // the NOT of the old flood-fill mask we saved earlier.
            cv::bitwise_and(m_scratchNotMask, m_floodFillMask,
                            m_perPointResults);
            // OK, now we have the results for just this point in per-point
            // results

            /// Initialize return value
            auto ret = static_cast<LedMeasurement>(origKeypoint);
            if (m_area <= 0) {
                // strange...
                return ret;
            }
            m_binarySubImage = m_perPointResults(m_filledBounds);
            computeContour();
            m_moments = haveContour() ? cv::moments(m_contour, false)
                                      : cv::moments(m_binarySubImage, true);

// the first two we are using from the keypoint description, the latter we can't
// always get (contour-based)
#if 0
            /// Estimate diameter
            ret.diameter = diameter();
            ret.area = area();
            if (haveContour()) {
                ret.circularity = circularity();
            }
#endif
            ret.knowBoundingBox = true;
            ret.boundingBox =
                cv::Size2f(m_filledBounds.width, m_filledBounds.height);
            return ret;
        }
Exemplo n.º 2
0
/* Find the dominant direction. Set corresponding weight to 1, and
   sets all other weights to 0. Set sumweight and sumcontour.*/
void 
weightWindow::makeD8(const dimension_type i, const dimension_type j,
		     const genericWindow<elevation_type>& elevwin, 
		     const direction_type dir,
		     const bool trustdir) {
  

  elevation_type elev_crt;
  short di,dj;
  elev_crt = elevwin.get(); 
  assert(!is_nodata(elev_crt));

  int maxi=0, maxj=0;
  double tanb, contour, maxtanb = -1, maxcontour = -1;
  /* map direction to neighbors */
  directionWindow dirwin(dir); 

  /* compute biggest angle to a neighbor */
  for (di=-1; di <=1; di++) {
    for (dj = -1; dj <= 1; dj++) {
      if (dirwin.get(di,dj)) {
	
	tanb = computeTanB(di,dj, elevwin);
	contour = computeContour(di, dj);
	
	if (tanb > maxtanb) {
	  maxtanb = tanb;
	  maxi = di;
	  maxj = dj;
	  maxcontour = contour;
	}
      }
    }
  }
  /* at this point maxi and maxj must be set */
  assert((maxi != 0 || maxj != 0) && maxtanb >= 0);
  
  /* set weights corresponding to this direction */
  init();   /* initialize all weights to 0 */
  int maxindex = 3* (maxi + 1) + maxj+1;
  weight.set(maxindex,1);   /* set maxweight to 1 */

  sumweight = 1;
  sumcontour = maxcontour;
}