Created
January 15, 2022 16:37
-
-
Save erap129/0a76f248b02922fe4354c545755e4d81 to your computer and use it in GitHub Desktop.
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
| def resize_image(image_data, max_img_width, max_img_height): | |
| scale_percent = min(max_img_width / image_data.shape[1], max_img_height / image_data.shape[0]) | |
| width = int(image_data.shape[1] * scale_percent) | |
| height = int(image_data.shape[0] * scale_percent) | |
| newSize = (width, height) | |
| image_resized = cv2.resize(image_data, newSize, None, None, None, cv2.INTER_AREA) | |
| return image_resized | |
| def pixmap_from_cv_image(cv_image): | |
| height, width, _ = cv_image.shape | |
| bytesPerLine = 3 * width | |
| qImg = QImage(cv_image.data, width, height, bytesPerLine, QImage.Format.Format_RGB888).rgbSwapped() | |
| return QPixmap(qImg) | |
| def get_image_mask(img, blue_shade, diff): | |
| lower = np.array([max(0, val) for val in [blue_shade[2]-diff, blue_shade[1]-diff, blue_shade[0]-diff]], dtype=np.uint8) | |
| upper = np.array([min(255, val) for val in [blue_shade[2]+diff, blue_shade[1]+diff, blue_shade[0]+diff]], dtype=np.uint8) | |
| mask = cv2.inRange(img, lower, upper) | |
| percent_traced = np.sum(mask > 0) / (mask.shape[0] * mask.shape[1]) | |
| return cv2.cvtColor(mask, cv2.COLOR_BGR2RGB), percent_traced |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment