OpenCV Bounding Box

前端 未结 4 1722
一整个雨季
一整个雨季 2020-12-08 17:59

I am working on software using OpenCV in C++ environment. The objective is to detect a boxing glove and draw a bounding box around gloves contours.

4条回答
  •  一生所求
    2020-12-08 18:30

    as b_m mentioned, you need to apply the morphological operations. Then I'd do something like finding the largest contour in the image and draw the bounding box around that contour only. I had created the following function for a project of mine which I think will help you if used in a correct manner

    CvSeq* findLargestContour(CvSeq* contours){
    
      CvSeq* current_contour = contours;
      double largestArea = 0;
      CvSeq* largest_contour = NULL;
    
      // check we at least have some contours
    
      if (contours == NULL){return NULL;}
    
      while (current_contour != NULL){
    
          double area = fabs(cvContourArea(current_contour));
    
          if(area > largestArea){
              largestArea = area;
              largest_contour = current_contour;
          }
    
          current_contour = current_contour->h_next;
      }
    
      // return pointer to largest
    
      return largest_contour;
    
    }
    

提交回复
热议问题