Files
onvif-go/examples/imaging-settings/main.go
T
ProtoTess b4e4982876 Refactor XML response handling in device extended and security tests
- Adjusted formatting in XML response strings for consistency in device_extended_test.go and device_security_test.go.
- Improved readability by aligning XML declaration and body content.
- Updated mock server responses to ensure proper handling of various ONVIF operations.

Enhance device security and storage handling

- Refactored struct field declarations in device_security.go and device_storage_test.go for improved clarity.
- Ensured consistent formatting across struct definitions and XML tags.

Standardize whitespace and formatting across multiple files

- Removed unnecessary blank lines and adjusted indentation in discovery, imaging, media, and PTZ server files.
- Improved overall code readability and maintainability by ensuring consistent formatting.

Update example applications for better readability

- Cleaned up whitespace in example applications to enhance code clarity.
- Ensured consistent formatting in main.go files across various examples.

Refactor server and SOAP handler code for consistency

- Standardized struct field declarations and XML tag formatting in server and SOAP handler files.
- Improved readability by aligning struct fields and ensuring consistent use of whitespace.

General code cleanup and formatting adjustments

- Applied consistent formatting across various files, including types.go and test files.
- Enhanced readability by aligning struct fields and removing unnecessary blank lines.
2025-12-01 00:49:36 +00:00

144 lines
3.7 KiB
Go

package main
import (
"context"
"fmt"
"log"
"time"
"github.com/0x524a/onvif-go"
)
func main() {
// Camera connection details
endpoint := "http://192.168.1.100/onvif/device_service"
username := "admin"
password := "password"
fmt.Println("Connecting to ONVIF camera...")
// Create a new ONVIF client
client, err := onvif.NewClient(
endpoint,
onvif.WithCredentials(username, password),
onvif.WithTimeout(30*time.Second),
)
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
ctx := context.Background()
// Initialize client
if err := client.Initialize(ctx); err != nil {
log.Fatalf("Failed to initialize client: %v", err)
}
// Get profiles
profiles, err := client.GetProfiles(ctx)
if err != nil {
log.Fatalf("Failed to get profiles: %v", err)
}
if len(profiles) == 0 {
log.Fatal("No profiles found")
}
// Get video source token from profile
profile := profiles[0]
if profile.VideoSourceConfiguration == nil {
log.Fatal("No video source configuration found")
}
videoSourceToken := profile.VideoSourceConfiguration.SourceToken
fmt.Printf("Using video source: %s\n\n", videoSourceToken)
// Get current imaging settings
fmt.Println("Getting current imaging settings...")
settings, err := client.GetImagingSettings(ctx, videoSourceToken)
if err != nil {
log.Fatalf("Failed to get imaging settings: %v", err)
}
fmt.Println("\nCurrent Imaging Settings:")
if settings.Brightness != nil {
fmt.Printf(" Brightness: %.2f\n", *settings.Brightness)
}
if settings.Contrast != nil {
fmt.Printf(" Contrast: %.2f\n", *settings.Contrast)
}
if settings.ColorSaturation != nil {
fmt.Printf(" Saturation: %.2f\n", *settings.ColorSaturation)
}
if settings.Sharpness != nil {
fmt.Printf(" Sharpness: %.2f\n", *settings.Sharpness)
}
if settings.IrCutFilter != nil {
fmt.Printf(" IR Cut Filter: %s\n", *settings.IrCutFilter)
}
if settings.Exposure != nil {
fmt.Printf(" Exposure Mode: %s\n", settings.Exposure.Mode)
if settings.Exposure.Mode == "MANUAL" {
fmt.Printf(" Exposure Time: %.2f\n", settings.Exposure.ExposureTime)
fmt.Printf(" Gain: %.2f\n", settings.Exposure.Gain)
}
}
if settings.Focus != nil {
fmt.Printf(" Focus Mode: %s\n", settings.Focus.AutoFocusMode)
}
if settings.WhiteBalance != nil {
fmt.Printf(" White Balance Mode: %s\n", settings.WhiteBalance.Mode)
}
if settings.WideDynamicRange != nil {
fmt.Printf(" WDR Mode: %s\n", settings.WideDynamicRange.Mode)
fmt.Printf(" WDR Level: %.2f\n", settings.WideDynamicRange.Level)
}
// Modify some settings
fmt.Println("\n\nModifying imaging settings...")
// Increase brightness
newBrightness := 60.0
settings.Brightness = &newBrightness
// Increase contrast
newContrast := 55.0
settings.Contrast = &newContrast
// Set to auto exposure
if settings.Exposure != nil {
settings.Exposure.Mode = "AUTO"
}
// Apply new settings
if err := client.SetImagingSettings(ctx, videoSourceToken, settings, true); err != nil {
log.Fatalf("Failed to set imaging settings: %v", err)
}
fmt.Println("Imaging settings updated successfully!")
// Verify changes
fmt.Println("\nVerifying new settings...")
updatedSettings, err := client.GetImagingSettings(ctx, videoSourceToken)
if err != nil {
log.Fatalf("Failed to get updated imaging settings: %v", err)
}
fmt.Println("\nUpdated Imaging Settings:")
if updatedSettings.Brightness != nil {
fmt.Printf(" Brightness: %.2f\n", *updatedSettings.Brightness)
}
if updatedSettings.Contrast != nil {
fmt.Printf(" Contrast: %.2f\n", *updatedSettings.Contrast)
}
if updatedSettings.Exposure != nil {
fmt.Printf(" Exposure Mode: %s\n", updatedSettings.Exposure.Mode)
}
fmt.Println("\nImaging settings demonstration complete!")
}