forked from ultralytics/yolov5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add crop image based on class detected
- Loading branch information
1 parent
83a0133
commit d3da375
Showing
3 changed files
with
62 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
train: ../train/images | ||
val: ../valid/images | ||
|
||
nc: 2 | ||
names: ['license-plate', 'vehicle'] |
This file contains 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 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,28 @@ | ||
import cv2 | ||
import torch | ||
import numpy as np | ||
|
||
from utils.general import (xywh2xyxy, xyxy2xywh) | ||
|
||
|
||
def crop(xyxy, im, square=False, gain=1.02, pad=10, BGR=False): | ||
xyxy = torch.tensor(xyxy).view(-1, 4) | ||
|
||
b = xyxy2xywh(xyxy) | ||
|
||
if square: | ||
b[:, 2:] = b[:, 2:].max(1)[0].unsqueeze(1) | ||
|
||
b[:, 2:] = b[:, 2:] * gain + pad | ||
|
||
xyxy = xywh2xyxy(b).long() | ||
|
||
crop = im[int(xyxy[0, 1]):int(xyxy[0, 3]), int(xyxy[0, 0]):int(xyxy[0, 2]), ::(1 if BGR else -1)] | ||
|
||
gray = cv2.cvtColor(crop, cv2.COLOR_RGB2GRAY) | ||
|
||
medBlur = cv2.medianBlur(gray, 3) | ||
|
||
gaussBlur = cv2.GaussianBlur(medBlur, (5, 5), 0) | ||
|
||
return gaussBlur |