- 
                Notifications
    
You must be signed in to change notification settings  - Fork 618
 
[Feature] Support CopyPaste for RotatedBoxes #657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Closed
      
      
    
  
     Closed
                    Changes from 3 commits
      Commits
    
    
            Show all changes
          
          
            5 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      1f97e24
              
                [Feature] Support CopyPaste for RotatedBoxes
              
              
                nijkah 203f7fa
              
                Add Docstring to RBitMasks
              
              
                nijkah 7b0dc3f
              
                Update mmrotate/datasets/pipelines/transforms.py
              
              
                nijkah 8f06194
              
                fix iou computation
              
              
                nijkah 8b328a4
              
                Merge branch 'dev' into feature/rcopypaste
              
              
                nijkah File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Copyright (c) OpenMMLab. All rights reserved. | ||
| from .structures import RBitmapMasks | ||
| 
     | 
||
| __all__ = ['RBitmapMasks'] | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Copyright (c) OpenMMLab. All rights reserved. | ||
| import cv2 | ||
| import numpy as np | ||
| from mmdet.core.mask import BitmapMasks | ||
| 
     | 
||
| 
     | 
||
| class RBitmapMasks(BitmapMasks): | ||
| """This class represents masks in the form of bitmaps. Compared to the | ||
| original class, this class supports getting the minimum area rectangles | ||
| from masks. | ||
| 
     | 
||
| Args: | ||
| masks (ndarray): ndarray of masks in shape (N, H, W), where N is | ||
| the number of objects. | ||
| height (int): height of masks | ||
| width (int): width of masks | ||
| """ | ||
| 
     | 
||
| def get_rbboxes(self): | ||
| num_masks = len(self) | ||
| rboxes = np.zeros((num_masks, 5), dtype=np.float32) | ||
| x_any = self.masks.any(axis=1) | ||
| y_any = self.masks.any(axis=2) | ||
| for idx in range(num_masks): | ||
| x = np.where(x_any[idx, :])[0] | ||
| y = np.where(y_any[idx, :])[0] | ||
| if len(x) > 0 and len(y) > 0: | ||
| contours = cv2.findContours(self.masks[idx], cv2.RETR_TREE, | ||
| cv2.CHAIN_APPROX_SIMPLE)[0][0] | ||
| (cx, cy), (w, h), a = cv2.minAreaRect(contours) | ||
| rboxes[idx, :] = np.array( | ||
| [cx, cy, w, h, np.radians(a)], dtype=np.float32) | ||
| return rboxes | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| # Copyright (c) OpenMMLab. All rights reserved. | ||
| from .loading import LoadPatchFromImage | ||
| from .transforms import PolyRandomRotate, RMosaic, RRandomFlip, RResize | ||
| from .transforms import (PolyRandomRotate, RCopyPaste, RMosaic, RRandomFlip, | ||
| RResize) | ||
| 
     | 
||
| __all__ = [ | ||
| 'LoadPatchFromImage', 'RResize', 'RRandomFlip', 'PolyRandomRotate', | ||
| 'RMosaic' | ||
| 'RMosaic', 'RCopyPaste' | ||
| ] | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we need to support
mmrotate.core.bbox.poly2obb_npfor various angle versions.However,
poly2obbsupposes that polygons have 4 vertices.How can we support this?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In mmrotate1.x, we suppose all rotated boxes use
ocangle version during data transforms.We only need to distinguish different angle versions within the box_head.
So I think it's OK to write like this.