コード例 #1
0
void ObjectDetector :: detect(const cv::Mat1f& distance_image,
                              cv::Mat1b& mask_image,
                              std::list<cv::Rect>& rects)
{
  if (mask_image.size() != distance_image.size())
    mask_image = cv::Mat1b(distance_image.size());

  for (int r = 0; r < distance_image.rows; ++r)
    for (int c = 0; c < distance_image.cols; ++c)
    {
      if (distance_image(r,c) >= m_min_threshold && distance_image(r,c) <= m_max_threshold)
        mask_image(r,c) = 255;
      else
        mask_image(r,c) = 0;
    }

  cv::morphologyEx(mask_image, mask_image,
                   cv::MORPH_OPEN,
                   getStructuringElement(cv::MORPH_RECT,
                                         cv::Size(3,3)));
  cv::morphologyEx(mask_image, mask_image,
                   cv::MORPH_CLOSE,
                   getStructuringElement(cv::MORPH_RECT,
                                         cv::Size(3,3)));

  std::vector< std::vector<cv::Point> > contours;
  cv::Mat1b contour_image = mask_image.clone();
  cv::findContours(contour_image, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
  for (int i = 0; i < contours.size(); ++i)
  {
    cv::Rect rect = cv::boundingRect(cv::Mat(contours[i]));
    if (rect.area() > 300)
      rects.push_back(rect);
  }
}
コード例 #2
0
ファイル: test_voronoi.cpp プロジェクト: mkgessen/voronoi
 void init(const cv::Mat1b & query,
           std::string implementation_name_,
           bool crop_img_before_) {
   _implementation_name = implementation_name_;
   _crop_img_before = crop_img_before_;
   _first_img = query.clone();
   VoronoiThinner::copy_bounding_box_plusone(query, _first_img, true);
   _curr_skel = _first_img.clone();
   // printf("first_img:%s\n", image_utils::infosImage(_first_img).c_str());
   _curr_iter = 1;
   _nframes = 0;
 }