(self, img)
| 192 | self._init(locals()) |
| 193 | |
| 194 | def get_transform(self, img): |
| 195 | if self.scale is not None: |
| 196 | scale = self._rand_range(self.scale[0], self.scale[1]) |
| 197 | else: |
| 198 | scale = 1.0 |
| 199 | |
| 200 | if self.translate_frac is not None: |
| 201 | max_dx = self.translate_frac[0] * img.shape[1] |
| 202 | max_dy = self.translate_frac[1] * img.shape[0] |
| 203 | dx = np.round(self._rand_range(-max_dx, max_dx)) |
| 204 | dy = np.round(self._rand_range(-max_dy, max_dy)) |
| 205 | else: |
| 206 | dx = 0 |
| 207 | dy = 0 |
| 208 | |
| 209 | if self.shear > 0.0: |
| 210 | shear = self._rand_range(-self.shear, self.shear) |
| 211 | sin_shear = math.sin(math.radians(shear)) |
| 212 | cos_shear = math.cos(math.radians(shear)) |
| 213 | else: |
| 214 | sin_shear = 0.0 |
| 215 | cos_shear = 1.0 |
| 216 | |
| 217 | center = (img.shape[1::-1] * np.array((0.5, 0.5))) - 0.5 |
| 218 | deg = self._rand_range(-self.rotate_max_deg, self.rotate_max_deg) |
| 219 | |
| 220 | transform_matrix = cv2.getRotationMatrix2D(tuple(center), deg, scale) |
| 221 | |
| 222 | # Apply shear : |
| 223 | if self.shear > 0.0: |
| 224 | m00 = transform_matrix[0, 0] |
| 225 | m01 = transform_matrix[0, 1] |
| 226 | m10 = transform_matrix[1, 0] |
| 227 | m11 = transform_matrix[1, 1] |
| 228 | transform_matrix[0, 1] = m01 * cos_shear + m00 * sin_shear |
| 229 | transform_matrix[1, 1] = m11 * cos_shear + m10 * sin_shear |
| 230 | # Add correction term to keep the center unchanged |
| 231 | tx = center[0] * (1.0 - m00) - center[1] * transform_matrix[0, 1] |
| 232 | ty = -center[0] * m10 + center[1] * (1.0 - transform_matrix[1, 1]) |
| 233 | transform_matrix[0, 2] = tx |
| 234 | transform_matrix[1, 2] = ty |
| 235 | |
| 236 | # Apply shift : |
| 237 | transform_matrix[0, 2] += dx |
| 238 | transform_matrix[1, 2] += dy |
| 239 | return WarpAffineTransform(transform_matrix, img.shape[1::-1], |
| 240 | self.interp, self.border, self.border_value) |
nothing calls this directly
no test coverage detected