Documentation
¶
Index ¶
- Constants
- func AddImageType(types ...string)
- func AddVideoType(types ...string)
- func CalculateDirectoryOrientation(directory string, mediaType string, recursive bool) (<-chan Result[Media], int)
- func CalculateFilesOrientation(filePaths []string) <-chan Result[Media]
- func Destroy()
- func Initialize(name string, onDownload func()) error
- type Media
- type Result
Constants ¶
const Version = "<version>"
Variables ¶
This section is empty.
Functions ¶
func AddImageType ¶
func AddImageType(types ...string)
AddImageType adds one or more image type extensions to the list of valid image types.
func AddVideoType ¶
func AddVideoType(types ...string)
AddVideoType adds one or more video type extensions to the list of valid video types.
func Destroy ¶
func Destroy()
Destroy cleans up resources used by the media orientation detection system.
This function performs cleanup operations to free memory and resources allocated during initialization. It should be called when the application is shutting down or when orientation detection functionality is no longer needed.
It's recommended to use this function with defer for proper cleanup:
Example: ¶
if err := mediaorient.Initialize("myapp", nil); err != nil {
log.Fatal("Initialization failed:", err)
}
defer mediaorient.Destroy() // Ensure cleanup on exit
func Initialize ¶
Initialize sets up the media orientation detection system by ensuring all required dependencies are available.
This function performs a three-step initialization process:
- Installs the ONNX runtime library if not already present in the user's config directory
- Downloads the latest image orientation model if needed or outdated
- Initializes the ONNX runtime session with the downloaded model
The name parameter specifies the application name used to create a dedicated config directory under the user's standard configuration path (e.g., ~/.config/name on Linux). It's important that you reuse the same name on later calls to Initialize() to ensure that the same config directory is used.
The onDownload callback function is called when the model needs to be downloaded, allowing the caller to notify users about the download process (e.g., show a progress indicator).
Returns an error if any step fails, including:
- Unable to create config directories or files
- Network errors during model download
- ONNX runtime initialization failures
Example: ¶
err := mediaorient.Initialize("myapp", func() {
fmt.Println("Downloading model, please wait...")
})
if err != nil {
log.Fatal("Failed to initialize:", err)
}
defer mediaorient.Destroy() // Clean up resources
Types ¶
type Media ¶
type Media struct {
// Name of the media.
Name string `json:"name"`
// Type of the media (e.g., image, video).
Type string `json:"type"`
// Rotation represents the rotation of the media.
Rotation int `json:"rotation"`
// Frames contain the image data of the media.
Frames []image.Image `json:"-"`
// Width represents the width of the media in pixels.
Width int `json:"width"`
// Height represents the height of the media in pixels.
Height int `json:"height"`
}
Media represents a media object.