streams - Optional

本文深入探讨了Java中Optional类型的使用,展示了如何通过Optional处理空值,避免NullPointerException。通过多个案例,如从空流中查找元素、Optional的基本操作及便利函数,阐述了Optional在流操作和错误处理中的作用。

Is there some kind of object we can use that will act as a holder for a stream element, but can also kindly tell us (that is, no exceptions) if the element we’re looking for isn’t there?

This idea is implemented as the Optional type. Certain standard stream operations return Optional objects because they cannot guarantee the desired result will exist.

case 1:

// streams/OptionalsFromEmptyStreams.java
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.

import java.util.*;
import java.util.stream.*;

class OptionalsFromEmptyStreams {
  public static void main(String[] args) {
    System.out.println(Stream.<String>empty().findFirst());
    System.out.println(Stream.<String>empty().findAny());
    System.out.println(Stream.<String>empty().max(String.CASE_INSENSITIVE_ORDER));
    System.out.println(Stream.<String>empty().min(String.CASE_INSENSITIVE_ORDER));
    System.out.println(Stream.<String>empty().reduce((s1, s2) -> s1 + s2));
    System.out.println(IntStream.empty().average());
  }
}
/* Output:
Optional.empty
Optional.empty
Optional.empty
Optional.empty
Optional.empty
OptionalDouble.empty
*/

case 2:

// streams/OptionalBasics.java
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.

import java.util.*;
import java.util.stream.*;

class OptionalBasics {
  static void test(Optional<String> optString) {
    if (optString.isPresent()) {
      System.out.println(optString.get());
    } else {
      System.out.println("Nothing inside!");
    }
  }

  public static void main(String[] args) {
    test(Stream.of("Epithets").findFirst());
    test(Stream.<String>empty().findFirst());
  }
}
/* Output:
Epithets
Nothing inside!
*/

case 3:

convenience functions

// streams/Optionals.java
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.

import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Optionals {
  static void basics(Optional<String> optString) {
    if (optString.isPresent()) {
      System.out.println(optString.get());
    } else {
      System.out.println("Nothing inside!");
    }
  }

  static void ifPresent(Optional<String> optString) {
    optString.ifPresent(System.out::println);
  }

  static void orElse(Optional<String> optString) {
    System.out.println(optString.orElse("Nada"));
  }

  static void orElseGet(Optional<String> optString) {
    System.out.println(optString.orElseGet(() -> "Generated"));
  }

  static void orElseThrow(Optional<String> optString) {
    try {
      System.out.println(optString.orElseThrow(() -> new Exception("Supplied")));
    } catch (Exception e) {
      System.out.println("Caught " + e);
    }
  }

  static void test(String testName, Consumer<Optional<String>> cos) {
    System.out.println(" === " + testName + " === ");
    cos.accept(Stream.of("Epithets").findFirst());
    cos.accept(Stream.<String>empty().findFirst());
  }

  public static void main(String[] args) {
    test("basics", Optionals::basics);
    test("ifPresent", Optionals::ifPresent);
    test("orElse", Optionals::orElse);
    test("orElseGet", Optionals::orElseGet);
    test("orElseThrow", Optionals::orElseThrow);
  }
}
/* Output:
 === basics ===
Epithets
Nothing inside!
 === ifPresent ===
Epithets
 === orElse ===
Epithets
Nada
 === orElseGet ===
Epithets
Generated
 === orElseThrow ===
Epithets
Caught java.lang.Exception: Supplied
*/

references:

1. On Java 8 - Bruce Eckel

2. https://github.com/wangbingfeng/OnJava8-Examples/blob/master/streams/OptionalsFromEmptyStreams.java

3. https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#empty--

4. https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html#toString--

5. http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/java/util/Optional.java

6. https://github.com/wangbingfeng/OnJava8-Examples/blob/master/streams/OptionalBasics.java

7. https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html#isPresent--

GetCapabilities Description: This method has been replaced by the more generic GetServices method. For capabilities of individual services refer to the GetServiceCapabilities methods. SOAP action: http://www.onvif.org/ver10/device/wsdl/GetCapabilities Input: [GetCapabilities] Category - optional, unbounded; [CapabilityCategory] List of categories to retrieve capability information on. - enum { 'All', 'Analytics', 'Device', 'Events', 'Imaging', 'Media', 'PTZ' } Output: [GetCapabilitiesResponse] Capabilities [Capabilities] Capability information. Analytics - optional; [AnalyticsCapabilities] Analytics capabilities XAddr [anyURI] Analytics service URI. RuleSupport [boolean] Indicates whether or not rules are supported. AnalyticsModuleSupport [boolean] Indicates whether or not modules are supported. Device - optional; [DeviceCapabilities] Device capabilities XAddr [anyURI] Device service URI. Network - optional; [NetworkCapabilities] Network capabilities. IPFilter - optional; [boolean] Indicates whether or not IP filtering is supported. ZeroConfiguration - optional; [boolean] Indicates whether or not zeroconf is supported. IPVersion6 - optional; [boolean] Indicates whether or not IPv6 is supported. DynDNS - optional; [boolean] Indicates whether or not is supported. Extension - optional; [NetworkCapabilitiesExtension] Dot11Configuration - optional; [boolean] Extension - optional; [NetworkCapabilitiesExtension2] System - optional; [SystemCapabilities] System capabilities. DiscoveryResolve [boolean] Indicates whether or not WS Discovery resolve requests are supported. DiscoveryBye [boolean] Indicates whether or not WS-Discovery Bye is supported. RemoteDiscovery [boolean] Indicates whether or not remote discovery is supported. SystemBackup [boolean] Indicates whether or not system backup is supported. SystemLogging [boolean] Indicates whether or not system logging is supported. FirmwareUpgrade [boolean] Indicates whether or not firmware upgrade is supported. SupportedVersions - unbounded; [OnvifVersion] Indicates supported ONVIF version(s). Major [int] Major version number. Minor [int] Two digit minor version number. If major version number is less than "16", X.0.1 maps to "01" and X.2.1 maps to "21" where X stands for Major version number. Otherwise, minor number is month of release, such as "06" for June. Extension - optional; [SystemCapabilitiesExtension] HttpFirmwareUpgrade - optional; [boolean] HttpSystemBackup - optional; [boolean] HttpSystemLogging - optional; [boolean] HttpSupportInformation - optional; [boolean] Extension - optional; [SystemCapabilitiesExtension2] IO - optional; [IOCapabilities] I/O capabilities. InputConnectors - optional; [int] Number of input connectors. RelayOutputs - optional; [int] Number of relay outputs. Extension - optional; [IOCapabilitiesExtension] Auxiliary - optional; [boolean] AuxiliaryCommands - optional, unbounded; [AuxiliaryData] Extension [IOCapabilitiesExtension2] Security - optional; [SecurityCapabilities] Security capabilities. TLS1.1 [boolean] Indicates whether or not TLS 1.1 is supported. TLS1.2 [boolean] Indicates whether or not TLS 1.2 is supported. OnboardKeyGeneration [boolean] Indicates whether or not onboard key generation is supported. AccessPolicyConfig [boolean] Indicates whether or not access policy configuration is supported. X.509Token [boolean] Indicates whether or not WS-Security X.509 token is supported. SAMLToken [boolean] Indicates whether or not WS-Security SAML token is supported. KerberosToken [boolean] Indicates whether or not WS-Security Kerberos token is supported. RELToken [boolean] Indicates whether or not WS-Security REL token is supported. Extension - optional; [SecurityCapabilitiesExtension] TLS1.0 [boolean] Extension - optional; [SecurityCapabilitiesExtension2] Dot1X [boolean] SupportedEAPMethod - optional, unbounded; [int] EAP Methods supported by the device. The int values refer to the IANA EAP Registry. RemoteUserHandling [boolean] Extension - optional; [DeviceCapabilitiesExtension] Events - optional; [EventCapabilities] Event capabilities XAddr [anyURI] Event service URI. WSSubscriptionPolicySupport [boolean] Indicates whether or not WS Subscription policy is supported. WSPullPointSupport [boolean] Indicates whether or not WS Pull Point is supported. WSPausableSubscriptionManagerInterfaceSupport [boolean] Indicates whether or not WS Pausable Subscription Manager Interface is supported. Imaging - optional; [ImagingCapabilities] Imaging capabilities XAddr [anyURI] Imaging service URI. Media - optional; [MediaCapabilities] Media capabilities XAddr [anyURI] Media service URI. StreamingCapabilities [RealTimeStreamingCapabilities] Streaming capabilities. RTPMulticast - optional; [boolean] Indicates whether or not RTP multicast is supported. RTP_TCP - optional; [boolean] Indicates whether or not RTP over TCP is supported. RTP_RTSP_TCP - optional; [boolean] Indicates whether or not RTP/RTSP/TCP is supported. Extension - optional; [RealTimeStreamingCapabilitiesExtension] Extension - optional; [MediaCapabilitiesExtension] ProfileCapabilities [ProfileCapabilities] MaximumNumberOfProfiles [int] Maximum number of profiles. PTZ - optional; [PTZCapabilities] PTZ capabilities XAddr [anyURI] PTZ service URI. Extension - optional; [CapabilitiesExtension] DeviceIO - optional; [DeviceIOCapabilities] XAddr [anyURI] VideoSources [int] VideoOutputs [int] AudioSources [int] AudioOutputs [int] RelayOutputs [int] Display - optional; [DisplayCapabilities] XAddr [anyURI] FixedLayout [boolean] Indication that the SetLayout command supports only predefined layouts. Recording - optional; [RecordingCapabilities] XAddr [anyURI] ReceiverSource [boolean] MediaProfileSource [boolean] DynamicRecordings [boolean] DynamicTracks [boolean] MaxStringLength [int] Search - optional; [SearchCapabilities] XAddr [anyURI] MetadataSearch [boolean] Replay - optional; [ReplayCapabilities] XAddr [anyURI] The address of the replay service. Receiver - optional; [ReceiverCapabilities] XAddr [anyURI] The address of the receiver service. RTP_Multicast [boolean] Indicates whether the device can receive RTP multicast streams. RTP_TCP [boolean] Indicates whether the device can receive RTP/TCP streams RTP_RTSP_TCP [boolean] Indicates whether the device can receive RTP/RTSP/TCP streams. SupportedReceivers [int] The maximum number of receivers supported by the device. MaximumRTSPURILength [int] The maximum allowed length for RTSP URIs. AnalyticsDevice - optional; [AnalyticsDeviceCapabilities] XAddr [anyURI] RuleSupport - optional; [boolean] Obsolete property. Extension - optional; [AnalyticsDeviceExtension] Extensions - optional; [CapabilitiesExtension2]这个接口该怎么回复一个支持media2的报文
10-12
profile M和profile G在以下这个函数上的区别GetProfiles Description: Retrieve the profile with the specified token or all defined media profiles. If no Type is provided the returned profiles shall contain no configuration information. If a single Type with value 'All' is provided the returned profiles shall include all associated configurations. Otherwise the requested list of configurations shall for each profile include the configurations present as Type. SOAP action: http://www.onvif.org/ver20/media/wsdl/GetProfiles Input: [GetProfiles] Token - optional; [ReferenceToken] Optional token of the requested profile. Type - optional, unbounded; [string] The types shall be provided as defined by tr2:ConfigurationEnumeration. Output: [GetProfilesResponse] Profiles - optional, unbounded; [MediaProfile] Lists all profiles that exist in the media service. The response provides the requested types of Configurations as far as available. If a profile doesn't contain a type no error shall be provided. token - required; [ReferenceToken] Unique identifier of the profile. fixed [boolean] A value of true signals that the profile cannot be deleted. Default is false. Name [Name] User readable name of the profile. Configurations - optional; [ConfigurationSet] The configurations assigned to the profile. VideoSource - optional; [VideoSourceConfiguration] Optional configuration of the Video input. token - required; [ReferenceToken] Token that uniquely references this configuration. Length up to 64 characters. Name [Name] User readable name. Length up to 64 characters. UseCount [int] Number of internal references currently using this configuration. This informational parameter is read-only. Deprecated for Media2 Service. ViewMode [string] Readonly parameter signalling Source configuration's view mode, for devices supporting different view modes as defined in tt:viewModes. SourceToken [ReferenceToken] Reference to the physical input. Bounds [IntRectangle] Rectangle specifying the Video capturing area. The capturing area shall not be larger than the whole Video source area. x - required; [int] y - required; [int] width - required; [int] height - required; [int] Extension - optional; [VideoSourceConfigurationExtension] Rotate - optional; [Rotate] Optional element to configure rotation of captured image. What resolutions a device supports shall be unaffected by the Rotate parameters. If a device is configured with Rotate=AUTO, the device shall take control over the Degree parameter and automatically update it so that a client can query current rotation. The device shall automatically apply the same rotation to its pan/tilt control direction depending on the following condition: if Reverse=AUTO in PTControlDirection or if the device doesn’t support Reverse in PTControlDirection Mode [RotateMode] Parameter to enable/disable Rotation feature. - enum { 'OFF', 'ON', 'AUTO' } Degree - optional; [int] Optional parameter to configure how much degree of clockwise rotation of image for On mode. Omitting this parameter for On mode means 180 degree rotation. Extension - optional; [RotateExtension] Extension - optional; [VideoSourceConfigurationExtension2] LensDescription - optional, unbounded; [LensDescription] Optional element describing the geometric lens distortion. Multiple instances for future variable lens support. FocalLength [float] Optional focal length of the optical system. Offset [LensOffset] Offset of the lens center to the imager center in normalized coordinates. x [float] Optional horizontal offset of the lens center in normalized coordinates. y [float] Optional vertical offset of the lens center in normalized coordinates. Projection - unbounded; [LensProjection] Radial description of the projection characteristics. The resulting curve is defined by the B-Spline interpolation over the given elements. The element for Radius zero shall not be provided. The projection points shall be ordered with ascending Radius. Items outside the last projection Radius shall be assumed to be invisible (black). Angle [float] Angle of incidence. Radius [float] Mapping radius as a consequence of the emergent angle. Transmittance - optional; [float] Optional ray absorption at the given angle due to vignetting. A value of one means no absorption. XFactor [float] Compensation of the x coordinate needed for the ONVIF normalized coordinate system. SceneOrientation - optional; [SceneOrientation] Optional element describing the scene orientation in the camera’s field of view. Mode [SceneOrientationMode] Parameter to assign the way the camera determines the scene orientation. - enum { 'MANUAL', 'AUTO' } Orientation - optional; [string] Assigned or determined scene orientation based on the Mode. When assigning the Mode to AUTO, this field is optional and will be ignored by the device. When assigning the Mode to MANUAL, this field is required and the device will return an InvalidArgs fault if missing. AudioSource - optional; [AudioSourceConfiguration] Optional configuration of the Audio input. token - required; [ReferenceToken] Token that uniquely references this configuration. Length up to 64 characters. Name [Name] User readable name. Length up to 64 characters. UseCount [int] Number of internal references currently using this configuration. This informational parameter is read-only. Deprecated for Media2 Service. SourceToken [ReferenceToken] Token of the Audio Source the configuration applies to VideoEncoder - optional; [VideoEncoder2Configuration] Optional configuration of the Video encoder. token - required; [ReferenceToken] Token that uniquely references this configuration. Length up to 64 characters. Name [Name] User readable name. Length up to 64 characters. UseCount [int] Number of internal references currently using this configuration. This informational parameter is read-only. Deprecated for Media2 Service. GovLength [int] Group of Video frames length. Determines typically the interval in which the I-Frames will be coded. An entry of 1 indicates I-Frames are continuously generated. An entry of 2 indicates that every 2nd image is an I-Frame, and 3 only every 3rd frame, etc. The frames in between are coded as P or B Frames. AnchorFrameDistance [int] Distance between anchor frames of type I-Frame and P-Frame. '1' indicates no B-Frames, '2' indicates that every 2nd frame is encoded as B-Frame, '3' indicates a structure like IBBPBBP..., etc. Profile [string] The encoder profile as defined in tt:VideoEncodingProfiles. GuaranteedFrameRate [boolean] A value of true indicates that frame rate is a fixed value rather than an upper limit, and that the video encoder shall prioritize frame rate over all other adaptable configuration values such as bitrate. Default is false. Signed [boolean] Indicates if this stream will be signed according to the Media Signing Specification. Encoding [string] Video Media Subtype for the video format. For definitions see tt:VideoEncodingMimeNames and IANA Media Types. Resolution [VideoResolution2] Configured video resolution Width [int] Number of the columns of the Video image. If there is a 90-degree rotation, this represents the number of lines of the Video image. Height [int] Number of the lines of the Video image. If there is a 90-degree rotation, this represents the number of columns of the Video image. RateControl - optional; [VideoRateControl2] Optional element to configure rate control related parameters. ConstantBitRate [boolean] Enforce constant bitrate. FrameRateLimit [float] Desired frame rate in fps. The actual rate may be lower due to e.g. performance limitations. BitrateLimit [int] the maximum output bitrate in kbps Multicast - optional; [MulticastConfiguration] Defines the multicast settings that could be used for video streaming. Address [IPAddress] The multicast address (if this address is set to 0 no multicast streaming is enaled) Type [IPType] Indicates if the address is an IPv4 or IPv6 address. - enum { 'IPv4', 'IPv6' } IPv4Address - optional; [IPv4Address] IPv4 address. IPv6Address - optional; [IPv6Address] IPv6 address Port [int] The RTP mutlicast destination port. A device may support RTCP. In this case the port value shall be even to allow the corresponding RTCP stream to be mapped to the next higher (odd) destination port number as defined in the RTSP specification. TTL [int] In case of IPv6 the TTL value is assumed as the hop limit. Note that for IPV6 and administratively scoped IPv4 multicast the primary use for hop limit / TTL is to prevent packets from (endlessly) circulating and not limiting scope. In these cases the address contains the scope. AutoStart [boolean] Read only property signalling that streaming is persistant. Use the methods StartMulticastStreaming and StopMulticastStreaming to switch its state. Quality [float] Relative value for the video quantizers and the quality of the video. A high value within supported quality range means higher quality AudioEncoder - optional; [AudioEncoder2Configuration] Optional configuration of the Audio encoder. token - required; [ReferenceToken] Token that uniquely references this configuration. Length up to 64 characters. Name [Name] User readable name. Length up to 64 characters. UseCount [int] Number of internal references currently using this configuration. This informational parameter is read-only. Deprecated for Media2 Service. Encoding [string] Audio Media Subtype for the audio format. For definitions see tt:AudioEncodingMimeNames and IANA Media Types. Multicast - optional; [MulticastConfiguration] Optional multicast configuration of the audio stream. Address [IPAddress] The multicast address (if this address is set to 0 no multicast streaming is enaled) Type [IPType] Indicates if the address is an IPv4 or IPv6 address. - enum { 'IPv4', 'IPv6' } IPv4Address - optional; [IPv4Address] IPv4 address. IPv6Address - optional; [IPv6Address] IPv6 address Port [int] The RTP mutlicast destination port. A device may support RTCP. In this case the port value shall be even to allow the corresponding RTCP stream to be mapped to the next higher (odd) destination port number as defined in the RTSP specification. TTL [int] In case of IPv6 the TTL value is assumed as the hop limit. Note that for IPV6 and administratively scoped IPv4 multicast the primary use for hop limit / TTL is to prevent packets from (endlessly) circulating and not limiting scope. In these cases the address contains the scope. AutoStart [boolean] Read only property signalling that streaming is persistant. Use the methods StartMulticastStreaming and StopMulticastStreaming to switch its state. Bitrate [int] The output bitrate in kbps. SampleRate [int] The output sample rate in kHz. Analytics - optional; [VideoAnalyticsConfiguration] Optional configuration of the analytics module and rule engine. token - required; [ReferenceToken] Token that uniquely references this configuration. Length up to 64 characters. Name [Name] User readable name. Length up to 64 characters. UseCount [int] Number of internal references currently using this configuration. This informational parameter is read-only. Deprecated for Media2 Service. AnalyticsEngineConfiguration [AnalyticsEngineConfiguration] AnalyticsModule - optional, unbounded; [Config] Name - required; [string] Name of the configuration. Type - required; [QName] The Type attribute specifies the type of rule and shall be equal to value of one of Name attributes of ConfigDescription elements returned by GetSupportedRules and GetSupportedAnalyticsModules command. Parameters [ItemList] List of configuration parameters as defined in the corresponding description. SimpleItem - optional, unbounded; Value name pair as defined by the corresponding description. Name - required; [string] Item name. Value - required; [anySimpleType] Item value. The type is defined in the corresponding description. ElementItem - optional, unbounded; Complex value structure. Name - required; [string] Item name. Extension - optional; [ItemListExtension] Extension - optional; [AnalyticsEngineConfigurationExtension] RuleEngineConfiguration [RuleEngineConfiguration] Rule - optional, unbounded; [Config] Name - required; [string] Name of the configuration. Type - required; [QName] The Type attribute specifies the type of rule and shall be equal to value of one of Name attributes of ConfigDescription elements returned by GetSupportedRules and GetSupportedAnalyticsModules command. Parameters [ItemList] List of configuration parameters as defined in the corresponding description. SimpleItem - optional, unbounded; Value name pair as defined by the corresponding description. Name - required; [string] Item name. Value - required; [anySimpleType] Item value. The type is defined in the corresponding description. ElementItem - optional, unbounded; Complex value structure. Name - required; [string] Item name. Extension - optional; [ItemListExtension] Extension - optional; [RuleEngineConfigurationExtension] PTZ - optional; [PTZConfiguration] Optional configuration of the pan tilt zoom unit. token - required; [ReferenceToken] Token that uniquely references this configuration. Length up to 64 characters. Name [Name] User readable name. Length up to 64 characters. UseCount [int] Number of internal references currently using this configuration. This informational parameter is read-only. Deprecated for Media2 Service. MoveRamp [int] The optional acceleration ramp used by the device when moving. PresetRamp [int] The optional acceleration ramp used by the device when recalling presets. PresetTourRamp [int] The optional acceleration ramp used by the device when executing PresetTours. NodeToken [ReferenceToken] A mandatory reference to the PTZ Node that the PTZ Configuration belongs to. DefaultAbsolutePantTiltPositionSpace - optional; [anyURI] If the PTZ Node supports absolute Pan/Tilt movements, it shall specify one Absolute Pan/Tilt Position Space as default. DefaultAbsoluteZoomPositionSpace - optional; [anyURI] If the PTZ Node supports absolute zoom movements, it shall specify one Absolute Zoom Position Space as default. DefaultRelativePanTiltTranslationSpace - optional; [anyURI] If the PTZ Node supports relative Pan/Tilt movements, it shall specify one RelativePan/Tilt Translation Space as default. DefaultRelativeZoomTranslationSpace - optional; [anyURI] If the PTZ Node supports relative zoom movements, it shall specify one Relative Zoom Translation Space as default. DefaultContinuousPanTiltVelocitySpace - optional; [anyURI] If the PTZ Node supports continuous Pan/Tilt movements, it shall specify one Continuous Pan/Tilt Velocity Space as default. DefaultContinuousZoomVelocitySpace - optional; [anyURI] If the PTZ Node supports continuous zoom movements, it shall specify one Continuous Zoom Velocity Space as default. DefaultPTZSpeed - optional; [PTZSpeed] If the PTZ Node supports absolute or relative PTZ movements, it shall specify corresponding default Pan/Tilt and Zoom speeds. PanTilt - optional; [Vector2D] Pan and tilt speed. The x component corresponds to pan and the y component to tilt. If omitted in a request, the current (if any) PanTilt movement should not be affected. Zoom - optional; [Vector1D] A zoom speed. If omitted in a request, the current (if any) Zoom movement should not be affected. DefaultPTZTimeout - optional; [duration] If the PTZ Node supports continuous movements, it shall specify a default timeout, after which the movement stops. PanTiltLimits - optional; [PanTiltLimits] The Pan/Tilt limits element should be present for a PTZ Node that supports an absolute Pan/Tilt. If the element is present it signals the support for configurable Pan/Tilt limits. If limits are enabled, the Pan/Tilt movements shall always stay within the specified range. The Pan/Tilt limits are disabled by setting the limits to –INF or +INF. Range [Space2DDescription] A range of pan tilt limits. URI [anyURI] A URI of coordinate systems. XRange [FloatRange] A range of x-axis. Min [float] Max [float] YRange [FloatRange] A range of y-axis. Min [float] Max [float] ZoomLimits - optional; [ZoomLimits] The Zoom limits element should be present for a PTZ Node that supports absolute zoom. If the element is present it signals the supports for configurable Zoom limits. If limits are enabled the zoom movements shall always stay within the specified range. The Zoom limits are disabled by settings the limits to -INF and +INF. Range [Space1DDescription] A range of zoom limit URI [anyURI] A URI of coordinate systems. XRange [FloatRange] A range of x-axis. Min [float] Max [float] Extension - optional; [PTZConfigurationExtension] PTControlDirection - optional; [PTControlDirection] Optional element to configure PT Control Direction related features. EFlip - optional; [EFlip] Optional element to configure related parameters for E-Flip. Mode [EFlipMode] Parameter to enable/disable E-Flip feature. - enum { 'OFF', 'ON', 'Extended' } Reverse - optional; [Reverse] Optional element to configure related parameters for reversing of PT Control Direction. Mode [ReverseMode] Parameter to enable/disable Reverse feature. - enum { 'OFF', 'ON', 'AUTO', 'Extended' } Extension - optional; [PTControlDirectionExtension] Extension - optional; [PTZConfigurationExtension2] Metadata - optional; [MetadataConfiguration] Optional configuration of the metadata stream. token - required; [ReferenceToken] Token that uniquely references this configuration. Length up to 64 characters. Name [Name] User readable name. Length up to 64 characters. UseCount [int] Number of internal references currently using this configuration. This informational parameter is read-only. Deprecated for Media2 Service. CompressionType [string] Optional parameter to configure compression type of Metadata payload. Use values from enumeration MetadataCompressionType. GeoLocation [boolean] Optional parameter to configure if the metadata stream shall contain the Geo Location coordinates of each target. ShapePolygon [boolean] Optional parameter to configure if the generated metadata stream should contain shape information as polygon. PTZStatus - optional; [PTZFilter] optional element to configure which PTZ related data is to include in the metadata stream Status [boolean] True if the metadata stream shall contain the PTZ status (IDLE, MOVING or UNKNOWN) Position [boolean] True if the metadata stream shall contain the PTZ position FieldOfView - optional; [boolean] True if the metadata stream shall contain the field-of-view information Events - optional; [EventSubscription] Optional element to configure the streaming of events. A client might be interested in receiving all, none or some of the events produced by the device: To get all events: Include the Events element but do not include a filter. To get no events: Do not include the Events element. To get only some events: Include the Events element and include a filter in the element. Filter - optional; [FilterType] SubscriptionPolicy - optional; Analytics - optional; [boolean] Defines whether the streamed metadata will include metadata from the analytics engines (video, cell motion, audio etc.) Multicast [MulticastConfiguration] Defines the multicast settings that could be used for video streaming. Address [IPAddress] The multicast address (if this address is set to 0 no multicast streaming is enaled) Type [IPType] Indicates if the address is an IPv4 or IPv6 address. - enum { 'IPv4', 'IPv6' } IPv4Address - optional; [IPv4Address] IPv4 address. IPv6Address - optional; [IPv6Address] IPv6 address Port [int] The RTP mutlicast destination port. A device may support RTCP. In this case the port value shall be even to allow the corresponding RTCP stream to be mapped to the next higher (odd) destination port number as defined in the RTSP specification. TTL [int] In case of IPv6 the TTL value is assumed as the hop limit. Note that for IPV6 and administratively scoped IPv4 multicast the primary use for hop limit / TTL is to prevent packets from (endlessly) circulating and not limiting scope. In these cases the address contains the scope. AutoStart [boolean] Read only property signalling that streaming is persistant. Use the methods StartMulticastStreaming and StopMulticastStreaming to switch its state. SessionTimeout [duration] The rtsp session timeout for the related audio stream (when using Media2 Service, this value is deprecated and ignored) AnalyticsEngineConfiguration - optional; [AnalyticsEngineConfiguration] Indication which AnalyticsModules shall output metadata. Note that the streaming behavior is undefined if the list includes items that are not part of the associated AnalyticsConfiguration. AnalyticsModule - optional, unbounded; [Config] Name - required; [string] Name of the configuration. Type - required; [QName] The Type attribute specifies the type of rule and shall be equal to value of one of Name attributes of ConfigDescription elements returned by GetSupportedRules and GetSupportedAnalyticsModules command. Parameters [ItemList] List of configuration parameters as defined in the corresponding description. SimpleItem - optional, unbounded; Value name pair as defined by the corresponding description. Name - required; [string] Item name. Value - required; [anySimpleType] Item value. The type is defined in the corresponding description. ElementItem - optional, unbounded; Complex value structure. Name - required; [string] Item name. Extension - optional; [ItemListExtension] Extension - optional; [AnalyticsEngineConfigurationExtension] Extension - optional; [MetadataConfigurationExtension] AudioOutput - optional; [AudioOutputConfiguration] Optional configuration of the Audio output. token - required; [ReferenceToken] Token that uniquely references this configuration. Length up to 64 characters. Name [Name] User readable name. Length up to 64 characters. UseCount [int] Number of internal references currently using this configuration. This informational parameter is read-only. Deprecated for Media2 Service. OutputToken [ReferenceToken] Token of the phsycial Audio output. SendPrimacy - optional; [anyURI] An audio channel MAY support different types of audio transmission. While for full duplex operation no special handling is required, in half duplex operation the transmission direction needs to be switched. The optional SendPrimacy parameter inside the AudioOutputConfiguration indicates which direction is currently active. An NVC can switch between different modes by setting the AudioOutputConfiguration. The following modes for the Send-Primacy are defined: www.onvif.org/ver20/HalfDuplex/Server The server is allowed to send audio data to the client. The client shall not send audio data via the backchannel to the NVT in this mode. www.onvif.org/ver20/HalfDuplex/Client The client is allowed to send audio data via the backchannel to the server. The NVT shall not send audio data to the client in this mode. www.onvif.org/ver20/HalfDuplex/Auto It is up to the device how to deal with sending and receiving audio data. Acoustic echo cancellation is out of ONVIF scope. OutputLevel [int] Volume setting of the output. The applicable range is defined via the option AudioOutputOptions.OutputLevelRange. AudioDecoder - optional; [AudioDecoderConfiguration] Optional configuration of the Audio decoder. token - required; [ReferenceToken] Token that uniquely references this configuration. Length up to 64 characters. Name [Name] User readable name. Length up to 64 characters. UseCount [int] Number of internal references currently using this configuration. This informational parameter is read-only. Deprecated for Media2 Service. Receiver - optional; [ReceiverConfiguration] Optional configuration of the Receiver. Mode [ReceiverMode] The following connection modes are defined: - AutoConnect: The receiver connects on demand, as required by consumers of the media streams. - AlwaysConnect: The receiver attempts to maintain a persistent connection to the configured endpoint. - NeverConnect: The receiver does not attempt to connect. - Unknown: This case should never happen. MediaUri [anyURI] Details of the URI to which the receiver should connect. StreamSetup [StreamSetup] Stream connection parameters. Stream [StreamType] Defines if a multicast or unicast stream is requested - enum { 'RTP-Unicast', 'RTP-Multicast' } Transport [Transport] Protocol [TransportProtocol] Defines the network protocol for streaming, either UDP=RTP/UDP, RTSP=RTP/RTSP/TCP or HTTP=RTP/RTSP/HTTP/TCP - enum { 'UDP', 'TCP', 'RTSP', 'HTTP' } Tunnel - optional; [Transport] Optional element to describe further tunnel options. This element is normally not needed Protocol [TransportProtocol] Defines the network protocol for streaming, either UDP=RTP/UDP, RTSP=RTP/RTSP/TCP or HTTP=RTP/RTSP/HTTP/TCP - enum { 'UDP', 'TCP', 'RTSP', 'HTTP' } Tunnel - optional; [Transport] Optional element to describe further tunnel options. This element is normally not needed ... is recursive token [ReferenceToken]
09-19
先展示下效果 https://pan.quark.cn/s/a4b39357ea24 遗传算法 - 简书 遗传算法的理论是根据达尔文进化论而设计出来的算法: 人类是朝着好的方向(最优解)进化,进化过程中,会自动选择优良基因,淘汰劣等基因。 遗传算法(英语:genetic algorithm (GA) )是计算数学中用于解决最佳化的搜索算法,是进化算法的一种。 进化算法最初是借鉴了进化生物学中的一些现象而发展起来的,这些现象包括遗传、突变、自然选择、杂交等。 搜索算法的共同特征为: 首先组成一组候选解 依据某些适应性条件测算这些候选解的适应度 根据适应度保留某些候选解,放弃其他候选解 对保留的候选解进行某些操作,生成新的候选解 遗传算法流程 遗传算法的一般步骤 my_fitness函数 评估每条染色体所对应个体的适应度 升序排列适应度评估值,选出 前 parent_number 个 个体作为 待选 parent 种群(适应度函数的值越小越好) 从 待选 parent 种群 中随机选择 2 个个体作为父方和母方。 抽取父母双方的染色体,进行交叉,产生 2 个子代。 (交叉概率) 对子代(parent + 生成的 child)的染色体进行变异。 (变异概率) 重复3,4,5步骤,直到新种群(parentnumber + childnumber)的产生。 循环以上步骤直至找到满意的解。 名词解释 交叉概率:两个个体进行交配的概率。 例如,交配概率为0.8,则80%的“夫妻”会生育后代。 变异概率:所有的基因中发生变异的占总体的比例。 GA函数 适应度函数 适应度函数由解决的问题决定。 举一个平方和的例子。 简单的平方和问题 求函数的最小值,其中每个变量的取值区间都是 [-1, ...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值