Camera calling method and system supporting multiple platforms
By acquiring system and camera configuration parameters and combining them with timer-based data collection, the black screen issue in cross-platform camera calls was resolved, enabling stable cross-platform camera calls and data display.
Patent Information
- Application Number
- CN202410907635.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-08
- Publication Date
- 2024-11-01
AI Technical Summary
Different platforms have complexities and black screen issues when accessing the camera, especially under Linux systems where inconsistent camera interfaces cause the camera to fail to capture images properly.
By acquiring system and camera information, configuring camera parameters, and using a timer to collect data, cross-platform camera access can be achieved, avoiding black screen issues.
The camera was successfully accessed and data was collected on different platforms, avoiding black screen issues and improving cross-platform compatibility and stability.
Smart Images

Figure CN118890541A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of camera platform docking, and in particular to a camera calling method and system supporting multiple platforms. Background Art
[0002] At present, more and more devices need to be equipped with cameras. The more devices there are, the more software needs to implement camera call functions on different platforms to obtain real-time image data. Different platforms use other third-party libraries, which are complicated to call in the Linux system, and there will be some interference, causing the function to operate abnormally. In addition, it is possible that the camera cannot capture the picture normally due to the inconsistency of the USB connected to different cameras, resulting in a black screen.
[0003] Therefore, a method is now needed that can call the camera on different platforms and obtain the camera acquisition data. Summary of the invention
[0004] To solve the above problems, the present invention provides a camera calling method and system that supports multiple platforms. By obtaining system information and configuring the camera according to different system information, the camera is called or switched according to instructions, thereby solving the problem that the prior art cannot normally call the camera on different platforms.
[0005] To achieve the above object, the present invention provides the following technical solutions:
[0006] A camera calling method supporting multiple platforms includes the following steps:
[0007] S1. Get the current platform system information and camera information, the camera is one or more, and set the camera configuration parameters in combination with the platform system information;
[0008] S2. In response to the camera call instruction, the corresponding camera is started according to the camera configuration parameters;
[0009] S3. Create a timer, and display the data collected by the started camera in combination with the timer.
[0010] Furthermore, in step S1, the current platform system information is obtained, and its specific implementation method includes: using the IsOSPlatform method under the RuntimeInformation class in the OpenCvSharp library to obtain the type of operating system used by the current platform.
[0011] Further, in step S2, the camera configuration parameters are set in combination with the platform system information, specifically including: setting the OpenCvSharp.VideoCaptureAPIs parameters in the OpenCvSharp library according to the type of operating system used by the current platform.
[0012] Furthermore, in step S2, the camera configuration parameters are set in combination with the platform system information, and further includes: sorting the cameras in the order of access to the platform, and numbering the cameras in sequence starting from 0 according to the sorting, and the camera calling instruction includes the number of the camera to be enabled.
[0013] Further, in step S2, when the camera calling instruction does not specify the camera to be enabled, the platform starts the camera numbered 0 by default.
[0014] Furthermore, in step S3, the creation of a timer is specifically implemented by instantiating a thread timer, the thread timer being a Timer object, and the triggering frequency of the thread timer being the same as the data acquisition frame rate of the started camera.
[0015] Furthermore, in step S3, the combined timer displays the data collected by the activated camera, and its specific implementation method includes: monitoring the triggering status of the timer, and executing the Read method in the VideoCapture class once each time the timer is triggered to read the image data collected by the activated camera.
[0016] Further, in step S3, the combined timer displays the data collected by the started camera, specifically including: using the OpenCvSharp library to create a Mat object, assigning the picture data collected by the started camera to the Mat object, and converting the Mat object into bitmap type data for display.
[0017] Furthermore, the method is based on the Avalonia framework.
[0018] Through the above technical scheme, the present invention has the following beneficial effects: by obtaining system information and camera information, the camera is configured according to the system information to ensure that the camera can be called normally on different platforms, and the camera acquisition data is collected in combination with a timer, thereby avoiding the black screen phenomenon caused by the camera's inability to capture the picture normally on different platforms. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 The present invention is a schematic diagram of the overall process of a camera calling method supporting multiple platforms.
[0020] Figure 2The present invention is a schematic diagram of the structure of a camera calling system supporting multiple platforms in an embodiment of the present invention. DETAILED DESCRIPTION
[0021] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0022] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0023] Example 1
[0024] See also Figure 1 , a camera calling method supporting multiple platforms, comprising the following steps: S1. obtaining current platform system information and camera information, the camera being one or more, and setting camera configuration parameters in combination with the platform system information;
[0025] S2. In response to the camera call instruction, the corresponding camera is started according to the camera configuration parameters;
[0026] S3. Create a timer, and display the data collected by the started camera in combination with the timer.
[0027] In an optional embodiment, in step S1, the current platform system information is obtained, and its specific implementation method includes: using the IsOSPlatform method under the RuntimeInformation class in the OpenCvSharp library to obtain the type of operating system used by the current platform.
[0028] The IsOSPlatform method can be used to directly obtain the operating system of the current platform, so as to set parameters in the constructor of the VideoCapture class of OpenCvSharp according to different operating systems.
[0029] In an optional embodiment, in step S2, setting the configuration parameters of the camera in combination with the platform system information specifically includes: setting the OpenCvSharp.VideoCaptureAPIs parameters in the OpenCvSharp library according to the type of operating system used by the current platform.
[0030] When the operating system used by the current platform is Windows, it is set to the OpenCvSharp.VideoCaptureAPIs.DSHOW parameter; when the operating system used is Linux, it corresponds to the OpenCvSharp.VideoCaptureAPIs.V4L2 parameter.
[0031] This method mainly uses the OpenCvSharp library, which directly encapsulates more OpenCV methods. At the same time, compared with other libraries, this library is more suitable for use in .net cross-platform projects. When released on different operating systems, it will not be affected by the lack of too many dependencies, which will cause the project to fail to run on systems other than Windows. It is simple and quick to handle.
[0032] In an optional embodiment, in step S2, the camera configuration parameters are set in combination with the platform system information, and further includes: sorting the cameras in the order of access to the platform, and numbering the cameras in sequence starting from 0 according to the sorting, and the camera call instruction includes the number of the camera to be enabled.
[0033] This method displays the names of all cameras in the system in a drop-down box so that users can flexibly switch cameras. The index of the first item in the drop-down box control is 0, so for easy calling, the cameras are encoded incrementally starting from 0 in the order of access.
[0034] In an optional embodiment, in step S2, when the camera calling instruction does not specify the camera to be enabled, the platform starts the camera numbered 0 by default.
[0035] In an optional embodiment, in step S3, a timer is created, and its specific implementation method includes: instantiating a thread timer, the thread timer is a Timer object, and the triggering frequency of the thread timer is the same as the data acquisition frame rate of the started camera.
[0036] In a specific embodiment, the trigger frequency of the thread timer is set to once every 33 ms.
[0037] In an optional embodiment, in step S3, the combined timer displays the data collected by the started camera, and its specific implementation method includes: monitoring the triggering status of the timer, executing the Read method in the VideoCapture class once each time the timer is triggered, and reading the image data collected by the started camera.
[0038] In the specific implementation, we subscribe to the method to be executed for the Elapsed event of the Timer object to collect camera data at a regular interval.
[0039] In an optional embodiment, in step S3, the combined timer displays the data collected by the started camera, specifically including: using the OpenCvSharp library to create a Mat object, assigning the picture data collected by the started camera to the Mat object, and converting the Mat object into bitmap type data for display.
[0040] We define the Mat frame data object in OpenCvSharp to receive the screen data read by the Read method under the VideoCapture class. The Mat object is passed in as the parameter of the Read method, and then the acquired frame data is automatically assigned to the passed-in Mat object. Then the Mat object needs to be converted into bitmap type data under Avalonia for binding and display on the Image control, and finally the Mat object is released.
[0041] The specific method of converting the Mat object into bitmap type data under Avalonia is: instantiate a memory stream object to obtain the memory stream converted from the data frame, and pass it as a parameter to the Bitmap construction method under Avalonia.
[0042] In an optional embodiment, the method is based on the Avalonia framework.
[0043] It is implemented through the Avalonia framework and supports multiple operating systems, including Windows, Linux, and macOS. This makes Avalonia more flexible and can meet the application requirements of different operating systems, so the camera call function can be implemented on multiple platforms.
[0044] Example 2
[0045] See also Figure 2 , a camera calling system supporting multiple platforms, including:
[0046] A parameter configuration module, used to obtain current platform system information and camera information, where there are one or more cameras, and to set camera configuration parameters in combination with the platform system information;
[0047] A camera calling module, used to respond to a camera calling instruction and start a corresponding camera according to camera configuration parameters;
[0048] The image display module is used to create a timer and display the data collected by the activated camera in combination with the timer.
[0049] The embodiment disclosed in this specification is only an example of a unilateral feature of the present invention, and the protection scope of the present invention is not limited to this embodiment, and any other functionally equivalent embodiments fall within the protection scope of the present invention. For those skilled in the art, various other corresponding changes and deformations can be made according to the technical solutions and concepts described above, and all of these changes and deformations should fall within the protection scope of the claims of the present invention.
Claims
1. A camera calling method supporting multiple platforms, characterized in that: The following steps are involved: S1. Obtain the current platform system information and camera information, where the camera is one or more, and set the camera configuration parameters in combination with the platform system information; S2. In response to the camera call instruction, the corresponding camera is started according to the camera configuration parameters; S3. Create a timer, and display the data collected by the started camera in combination with the timer.
2. A camera calling method supporting multiple platforms according to claim 1, characterized in that: In step S1, the current platform system information is obtained, and its specific implementation method includes: using the IsOSPlatform method under the RuntimeInformation class in the OpenCvSharp library to obtain the type of operating system used by the current platform.
3. A camera calling method supporting multiple platforms according to claim 2, characterized in that: In step S2, the configuration parameters of the camera are set in combination with the platform system information, specifically including: setting the OpenCvSharp.VideoCaptureAPIs parameters in the OpenCvSharp library according to the type of operating system used by the current platform.
4. The camera calling method supporting multiple platforms according to claim 1, characterized in that: In step S2, the camera configuration parameters are set in combination with the platform system information, and further includes: sorting the cameras in the order of access to the platform, and numbering the cameras in sequence starting from 0 according to the sorting, and the camera calling instruction includes the number of the camera to be enabled.
5. A camera calling method supporting multiple platforms according to claim 4, characterized in that: In step S2, when the camera calling instruction does not specify the camera to be enabled, the platform starts the camera numbered 0 by default.
6. The camera calling method supporting multiple platforms according to claim 1, characterized in that: In step S3, a timer is created, and its specific implementation method includes: instantiating a thread timer, the thread timer is a Timer object, and the triggering frequency of the thread timer is the same as the data acquisition frame rate of the started camera.
7. A camera calling method supporting multiple platforms according to claim 6, characterized in that: In step S3, the combined timer displays the data collected by the activated camera, and its specific implementation method includes: monitoring the triggering status of the timer, executing the Read method in the VideoCapture class once each time the timer is triggered, and reading the image data collected by the activated camera.
8. A camera calling method supporting multiple platforms according to claim 7, characterized in that: In step S3, the combined timer displays the data collected by the started camera, specifically including: using the OpenCvSharp library to create a Mat object, assigning the picture data collected by the started camera to the Mat object, and converting the Mat object into bitmap type data for display.
9. The camera calling method supporting multiple platforms according to claim 1, characterized in that: The method is based on the Avalonia framework.
10. A camera calling system supporting multiple platforms, characterized in that: include: A parameter configuration module, used to obtain current platform system information and camera information, where there are one or more cameras, and to set camera configuration parameters in combination with the platform system information; A camera calling module, used to respond to a camera calling instruction and start a corresponding camera according to camera configuration parameters; The image display module is used to create a timer and display the data collected by the started camera in combination with the timer.
