generated from ultralytics/template
-
-
Notifications
You must be signed in to change notification settings - Fork 76
Open
Labels
enhancementNew feature or requestNew feature or requestquestionFurther information is requestedFurther information is requestedsolutionsUltralytics Solutions issues, PR's, DiscussionsUltralytics Solutions issues, PR's, Discussions
Description
I saw getCorrectOrientationUIImage here:
yolo-ios-app/ExampleApps/YOLOSingleImageSwiftUI/YOLOSingleImageSwiftUI/ContentView.swift
Lines 68 to 94 in f43e8ed
| /// Corrects the orientation of an image to ensure proper processing by the YOLO model. | |
| /// | |
| /// Images from the photo library might have orientation metadata rather than correctly oriented pixels. | |
| /// This function ensures the image is properly oriented for processing by the YOLO model. | |
| /// | |
| /// - Parameter uiImage: The input image that may have incorrect orientation metadata. | |
| /// - Returns: A new UIImage with the correct orientation for processing. | |
| func getCorrectOrientationUIImage(uiImage: UIImage) -> UIImage { | |
| var newImage = UIImage() | |
| let ciContext = CIContext() | |
| switch uiImage.imageOrientation.rawValue { | |
| case 1: | |
| guard let orientedCIImage = CIImage(image: uiImage)?.oriented(CGImagePropertyOrientation.down), | |
| let cgImage = ciContext.createCGImage(orientedCIImage, from: orientedCIImage.extent) | |
| else { return uiImage } | |
| newImage = UIImage(cgImage: cgImage) | |
| case 3: | |
| guard let orientedCIImage = CIImage(image: uiImage)?.oriented(CGImagePropertyOrientation.right), | |
| let cgImage = ciContext.createCGImage(orientedCIImage, from: orientedCIImage.extent) | |
| else { return uiImage } | |
| newImage = UIImage(cgImage: cgImage) | |
| default: | |
| newImage = uiImage | |
| } | |
| return newImage | |
| } |
Now I'm wondering when it DO or DON'T have to call that before passing an image to YOLO predict!?
Is it "safe" to always call it or can that screw up orientation?
Is there some way I can tell if my image has correct orientation?
Would it make sense that you move that function into the package for easier re-use?
(currently I copy & paste it into my project)
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestquestionFurther information is requestedFurther information is requestedsolutionsUltralytics Solutions issues, PR's, DiscussionsUltralytics Solutions issues, PR's, Discussions