A path positioning method, apparatus, device, and storage medium for a camera device.
By executing the udevadm command on a USB camera device in a Linux system, device attributes are obtained and standardized, and a stable device identifier is generated. This solves the configuration failure problem caused by changes in USB camera serial numbers, and achieves stability in device identification and continuity in the production system.
Patent Information
- Application Number
- CN202611169931.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-04
- Publication Date
- 2026-11-17
AI Technical Summary
In Linux systems, the dynamic changes in the USB camera device number cause configuration failures, affecting production efficiency and system reliability, and existing technologies cannot effectively solve this problem.
By executing the udevadm command on a USB camera device in a Linux system, device attributes are obtained, parsed, and normalized to generate a stable device identifier. A mapping relationship is established and written to a configuration file, and the device identifier is dynamically matched to determine the device path.
This feature enables USB camera devices to automatically take effect after system restart or hot-plugging, improving the stability of device recognition, avoiding manual reconfiguration, and ensuring the continuity of the production system.
Smart Images

Figure CN123123540A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a path positioning method, apparatus, device, and storage medium for a camera device. Background Technology
[0002] In industrial vision inspection systems, multiple USB cameras are typically deployed simultaneously to perform product quality inspection. In Linux systems, USB cameras are identified as device nodes such as / dev / video0 and / dev / video1, with these numbers dynamically assigned by the kernel during device enumeration. When the system restarts, cameras are hot-plugged, or the USB hub is reset, the device number may change; for example, / dev / video0 might become / dev / video2. This causes pre-configured parameters such as exposure, contrast, and alarm thresholds to become incompatible with the actual device, requiring manual re-identification and configuration, severely impacting production efficiency and system reliability.
[0003] Existing technologies mainly rely on Docker containers and modifications to the Android HAL layer, which require changes to the underlying system architecture, resulting in high implementation complexity. Furthermore, these technologies are only applicable to Android-compatible scenarios and cannot be adapted to general industrial Linux systems. Additionally, there are technologies that optimize frame acquisition efficiency through multiple coroutines and message queues, but these do not address the core issue of the stability of USB camera device recognition.
[0004] As can be seen from the above, how to avoid configuration failure caused by dynamic changes in the USB camera serial number under Linux system is an urgent problem to be solved. Summary of the Invention
[0005] In view of this, the purpose of this invention is to provide a path positioning method, apparatus, device, and storage medium for camera devices, which can prevent configuration failure caused by dynamic changes in the USB camera ID under Linux systems. The specific solution is as follows: Firstly, this application provides a path positioning method for a camera device, including: The target udevadm command is executed on each USB camera device in the Linux system. Based on the command execution result and a preset determination mechanism, the target USB camera device is determined from the USB camera devices, and the device attributes corresponding to the target USB camera device are obtained. The device attributes include physical topology path, manufacturer number, product number, and device serial number. The physical topology path in the device attributes is parsed to obtain the corresponding parsing result. Based on the parsing result, it is normalized using regular expressions to obtain a normalized path. The normalized path, the manufacturer number, the product number, and the device serial number are combined to obtain a device feature string. The device feature string is hashed to obtain a device identifier. Establish a mapping relationship between the device identifier of the target USB camera device and the corresponding service configuration information, and write the mapping relationship into the target configuration file; When a target drift event occurs in the Linux system, the system obtains the USB camera devices that the application needs to start, determines the startup identifier corresponding to the USB camera device from the target configuration file, identifies the USB camera devices that have completed USB bus enumeration in the Linux system as the new USB camera devices, and then jumps to the step of executing the target udevadm command on each USB camera device in the Linux system to obtain the target device identifier; the target drift event includes Linux system restart and hot-plugging of USB camera devices; The target device identifier is matched with the identifier to be started, and the target device path of the USB camera device to be started in the Linux system is determined by using the matching results.
[0006] Optionally, the step of executing the target udevadm command on each USB camera device in the Linux system, and determining the target USB camera device from the USB camera devices based on the obtained command execution results and using a preset determination mechanism, includes: The target udevadm command is executed on each USB camera device in the Linux system to obtain the corresponding device information. It is determined whether there is a manufacturer number in each device information. Based on the obtained determination result and each USB camera device, the USB camera devices that do not have a manufacturer number in the device information are removed to obtain the removed camera devices. If the field corresponding to the manufacturer number of the removed camera device contains the target USB substring, then the removed camera device is identified as the target USB camera device.
[0007] Optionally, parsing the physical topology path in the device attributes to obtain the corresponding parsing result, and then performing normalization processing based on the parsing result using regular expressions to obtain a normalized path, includes: The physical topology path in the device attributes is parsed to obtain the PCI controller location identifier, USB port path identifier, and interface number suffix; Regular expressions are used to match and remove the suffixes of the interface number to obtain a normalized path.
[0008] Optionally, the step of combining the normalized path, the manufacturer number, the product number, and the device serial number to obtain the device feature string includes: Determine whether the device attributes of the target USB camera device meet a first preset priority condition; the first preset priority condition is that the physical topology path in the device attributes meets a preset availability condition. If the first preset priority condition is met, the device feature string is obtained by combining the normalized path, the manufacturer number, the product number, and the device serial number. If the first preset priority condition is not met, the device feature string is obtained by combining the manufacturer number, the product number, and the device serial number.
[0009] Optionally, if the first preset priority condition is not met, the method of combining the manufacturer number, the product number, and the device serial number to obtain a device feature string further includes: If the device attributes of the target USB camera device do not meet the first preset priority condition, and all attributes in the device attributes are missing, then the device feature string is determined based on the original device path corresponding to the target USB camera device.
[0010] Optionally, after performing a hash calculation on the device feature string to obtain the device identifier, the method further includes: The device identifiers of the target USB camera device are detected, and based on the detection results, duplicate USB camera devices with duplicate device identifiers are identified. A new device feature string is determined based on the device number corresponding to the duplicate USB camera device, and the process jumps to the step of hashing the device feature string until the detection result indicates that there is no duplicate USB camera device with duplicate device identifier.
[0011] Optionally, the step of matching each of the target device identifiers with the identifier to be started, and using the matching results to determine the target device path of the USB camera device to be started in the Linux system, includes: The target device identifier is matched with the identifier to be started, and the target device index corresponding to the USB camera device to be started is determined by using the matching result; The target device path of the USB camera device to be started in the Linux system is determined based on the target device index.
[0012] Secondly, this application provides a path positioning device for a camera device, comprising: The device attribute acquisition module is used to execute the target udevadm command on each USB camera device in the Linux system, determine the target USB camera device from the USB camera devices based on the command execution result and a preset judgment mechanism, and obtain the device attributes corresponding to the target USB camera device; the device attributes include physical topology path, manufacturer number, product number and device serial number; The hash calculation module is used to parse the physical topology path in the device attributes to obtain the corresponding parsing result, and to perform normalization processing based on the parsing result using regular expressions to obtain a normalized path. The normalized path, the manufacturer number, the product number and the device serial number are combined to obtain a device feature string, and the device feature string is hashed to obtain a device identifier. The mapping relationship writing module is used to establish a mapping relationship between the device identifier of the target USB camera device and the corresponding service configuration information, and write the mapping relationship into the target configuration file; The target identifier determination module is used to, when a target drift event occurs in the Linux system, obtain the USB camera device to be started by the application, determine the startup identifier corresponding to the USB camera device to be started from the target configuration file, identify the USB camera devices that have completed USB bus enumeration in the Linux system as the new USB camera devices, and then jump to the step of executing the target udevadm command on each USB camera device in the Linux system to obtain the target device identifier; the target drift event includes Linux system restart and hot-plugging of USB camera devices; The target path determination module is used to match each of the target device identifiers with the identifier to be started, and use the matching results to determine the target device path of the USB camera device to be started in the Linux system.
[0013] Thirdly, this application provides an electronic device, comprising: Memory, used to store computer programs; A processor is used to execute the computer program to implement the aforementioned path positioning method for the camera device.
[0014] Fourthly, this application provides a computer-readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the aforementioned path positioning method for a camera device.
[0015] This application executes the target udevadm command on each USB camera device in a Linux system. Based on the command execution result and a preset judgment mechanism, it identifies the target USB camera device from among the USB camera devices and obtains the device attributes corresponding to the target USB camera device. The device attributes include physical topology path, manufacturer ID, product ID, and device serial number. The physical topology path in the device attributes is parsed to obtain the corresponding parsing result. Based on the parsing result, it is normalized using regular expressions to obtain a normalized path. The normalized path, manufacturer ID, product ID, and device serial number are combined to obtain a device feature string. The device feature string is hashed to obtain a device identifier. A relationship is established between the device identifier of the target USB camera device and the corresponding service configuration information. The mapping relationship is established and written into the target configuration file. When a target drift event occurs in the Linux system, the USB camera device to be started by the application is obtained. The startup identifier corresponding to the USB camera device to be started is determined from the target configuration file. Each USB camera device that has completed USB bus enumeration in the Linux system is identified as a new USB camera device. Then, the process jumps to the step of executing the target udevadm command on each USB camera device in the Linux system to obtain the target device identifier. The target drift event includes Linux system restart and hot-plugging of USB camera devices. The target device identifier is matched with the startup identifier, and the target device path of the USB camera device to be started in the Linux system is determined using the matching result.
[0016] As can be seen from the above, this application determines the target USB camera device by executing the target udevadm command on each USB camera device in the Linux system and using a preset judgment mechanism, thereby obtaining device attributes including physical topology path, manufacturer number, product number, and device serial number. Since the physical topology path is based on the physical connection relationship between the USB controller and the port, it is not affected by the system enumeration order. The physical topology path is parsed and regular expressions are used to remove dynamically changing interface number suffixes to obtain a normalized path. Then, a stable device identifier is generated by combining hardware characteristics, and a mapping relationship is established between the device identifier and the business configuration information and written into the target configuration file. When target drift events such as system restart or hot-plugging of USB camera devices occur, the target device identifiers are recalculated and matched with the identifier to be started, so as to accurately locate the target device path of the USB camera device to be started in the system. In this way, the configuration can take effect automatically after system restart or hot-plugging without manual reconfiguration, the stability of device identification is significantly improved, and the identification process only queries device information through system commands, without opening the camera device, avoiding interference with the camera in use and ensuring the continuity of the production system. Attached Figure Description
[0017] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0018] Figure 1 This is a flowchart of a path positioning method for a camera device disclosed in this application; Figure 2 This is a schematic diagram of the physical topology path normalization process disclosed in this application; Figure 3 This is a schematic diagram of a device identifier generation method disclosed in this application; Figure 4 This is a schematic diagram of a dynamic device query disclosed in this application; Figure 5 This application discloses a flowchart of a specific path positioning method for a camera device. Figure 6 This is a schematic diagram of the architecture of a path positioning method for a camera device disclosed in this application; Figure 7 This is a schematic diagram of the path positioning device of a camera device disclosed in this application; Figure 8 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation
[0019] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0020] Currently, the main approach involves modifying the Android HAL layer using Docker containers, which requires altering the underlying system architecture, resulting in high implementation complexity. Furthermore, this approach is only suitable for Android-compatible scenarios and cannot be adapted to general industrial Linux systems. While there are techniques that optimize frame acquisition efficiency using multiple coroutines and message queues, these do not address the core issue of stable USB camera device recognition. Therefore, this application provides a path positioning method for camera devices. The configuration automatically takes effect after system restarts and hot-plugging, eliminating the need for manual reconfiguration. This significantly improves the stability of device recognition. The recognition process only involves querying device information via system commands, without needing to open the camera device, thus avoiding interference with cameras in use and ensuring the continuity of the production system.
[0021] See Figure 1 As shown, this embodiment of the invention discloses a path positioning method for a camera device, including: Step S11: Execute the target udevadm command on each USB camera device in the Linux system. Based on the command execution result and using a preset judgment mechanism, determine the target USB camera device from the USB camera devices and obtain the device attributes corresponding to the target USB camera device. The device attributes include physical topology path, manufacturer number, product number and device serial number.
[0022] In this embodiment, when the Linux system starts, it can traverse each camera device node corresponding to / dev / video. For each device node, the target udevadm command is executed. Specifically, the target udevadm command can be "udevadm info --query=all --name= / dev / videoX" (where X is the device node number). Taking / dev / video0 as an example, after executing "udevadm info --query=all --name= / dev / video0", the returned command execution result (i.e., device information) is shown below: E: ID_VENDOR_ID=1bcf E: ID_MODEL_ID=28c4 E: ID_SERIAL_SHORT=01.00.00 E: ID_PATH=pci-0000:00:14.0-usb-0:10:1.0 Where ID_VENDOR_ID is the manufacturer ID, ID_MODEL_ID is the product ID, ID_SERIAL_SHORT is the device serial number, and ID_PATH is the physical topology path.
[0023] Understandably, the target USB camera device is determined from among the various USB camera devices using a preset judgment mechanism. The first judgment is to determine whether there is a manufacturer ID (ID_VENDOR_ID) in the device information. A normal UVC USB camera will contain a four-digit hexadecimal manufacturer ID in the output of udevadm. If a device node does not return a manufacturer ID, it means that it may be a virtual video device (such as v4l2loopback) or a MIPI-CSI camera that does not pass through the USB bus. Therefore, USB camera devices that do not have a manufacturer ID in their device information are removed to obtain the removed camera devices. The second layer of determination involves checking whether the physical topology path (i.e., the ID_PATH field) of the removed camera device contains the target USB substring "-usb-". The format of the physical topology path ID_PATH for a USB device is "pci-XXXX:XX:XX.X-usb-X:X:XX". By checking whether it contains the "-usb-" substring, it can be confirmed whether the device is a USB bus device. For example, the ID_PATH of a MIPI-CSI camera is "platform-xxxxxx", which does not contain "-usb-". If the physical topology path contains the target USB substring, then the removed camera device is determined to be the target USB camera device. It is worth mentioning that, as an optional third layer of determination, some UVC devices will return the DEVTYPE=usb_device attribute in the udevadm output. This attribute can be used as an auxiliary confirmation. That is, traversing each node of / dev / video and executing the udevadm query, if the ID_PATH in the returned result contains the "-usb-" substring and the ID_VENDOR_ID exists, then it is determined to be a USB camera device and processing continues; otherwise, it is skipped.
[0024] Specifically, the step of executing the target udevadm command on each USB camera device in the Linux system, and determining the target USB camera device from the USB camera devices based on the obtained command execution results and using a preset judgment mechanism, includes: executing the target udevadm command on each USB camera device in the Linux system to obtain the corresponding device information; determining whether there is a manufacturer number in each device information; based on the obtained judgment results and each USB camera device, removing USB camera devices whose device information does not contain a manufacturer number to obtain the removed camera devices; if the field corresponding to the manufacturer number of the removed camera device contains the target USB substring, then the removed camera device is determined as the target USB camera device.
[0025] It should be noted that this embodiment does not use the method of opening the camera device (such as by using cv2.VideoCapture().isOpened()) for device determination, because this method would actually open the device, thus interfering with a camera in use. This embodiment also does not rely on the / dev / v4l / by-id / symbolic link for determination, because streamlined embedded Linux systems do not create this symbolic link by default. Therefore, device determination can be completed simply by executing system commands to query device information, achieving zero interference with a running camera.
[0026] Step S12: Parse the physical topology path in the device attributes to obtain the corresponding parsing result. Based on the parsing result, perform normalization processing using regular expressions to obtain a normalized path. Combine the normalized path, the manufacturer number, the product number, and the device serial number to obtain a device feature string. Perform hash calculation on the device feature string to obtain the device identifier.
[0027] In this embodiment, the physical topology path in the device attributes is parsed to obtain the PCI controller location identifier, USB port path identifier, and interface number suffix. Taking the physical topology path "pci-0000:00:14.0-usb-0:10:1.0" as an example, "pci-0000:00:14.0" represents the physical location of the PCI (Peripheral Component Interconnect) controller (i.e., the PCI controller location identifier), "usb-0:10" represents the USB port path (i.e., the USB port path identifier), and ":1.0" represents the USB interface number (i.e., the interface number suffix).
[0028] Figure 2This diagram illustrates a physical topology path normalization process. Since the same physical camera may generate multiple / dev / video devices due to different USB interfaces (e.g., video streaming interface and control interface), and the physical topology paths of these devices differ only in the interface number portion at the end, regular expressions are used to match and remove these interface number suffixes to obtain a normalized path, ensuring consistent identification. In this embodiment, the regular expression `re.sub(r':\d+\.\d+$', '', id_path)` is used to match and remove interface number suffixes at the end of the physical topology path that conform to the format ":XX" (where X is a number). For example, "pci-0000:00:14.0-usb-0:10:1.0" is normalized to "pci-0000:00:14.0-usb-0:10".
[0029] Specifically, parsing the physical topology path in the device attributes to obtain the corresponding parsing result, and then using regular expressions to normalize the parsing result to obtain a normalized path, includes: parsing the physical topology path in the device attributes to obtain the PCI controller location identifier, USB port path identifier, and interface number suffix; and using regular expressions to match and remove the interface number suffix to obtain a normalized path.
[0030] In this embodiment, the device feature string is determined by combining the normalized path, manufacturer number, product number, and device serial number, using a hierarchical priority strategy. Specifically, it is determined whether the device attributes of the target USB camera device meet a first preset priority condition. The first preset priority condition is that the physical topology path in the device attributes meets a preset availability condition (i.e., the physical topology path is available). If the first preset priority condition is met, i.e., the physical topology path is available, then the device feature string is obtained by combining the normalized path, manufacturer number, product number, and device serial number. Taking the aforementioned data as an example, the combined device feature string is "pci-0000:00:14.0-usb-0:10" + "_" + "1bcf" + "_" + "28c4" + "_" + "01.00.00" = "pci-0000:00:14.0-usb-0:10_1bcf_28c4_01.00.00".
[0031] Furthermore, if the first preset priority condition is not met, i.e., the physical topology path is unavailable, the device feature string is obtained by combining the manufacturer number, product number, and device serial number, or by combining the original device path. If the first preset priority condition is not met, and all attributes in the device attributes (i.e., physical topology path, manufacturer number, product number, and device serial number) are missing, the device feature string is determined based on the original device path corresponding to the target USB camera device, wherein the original device path is the / dev / videoX device file path corresponding to the device in the current Linux system.
[0032] Specifically, the step of combining the normalized path, the manufacturer number, the product number, and the device serial number to obtain a device feature string includes: determining whether the device attributes of the target USB camera device meet a first preset priority condition; the first preset priority condition is that the physical topology path in the device attributes meets a preset availability condition; if the first preset priority condition is met, then the device feature string is obtained by combining the normalized path, the manufacturer number, the product number, and the device serial number; if the first preset priority condition is not met, then the device feature string is obtained by combining the manufacturer number, the product number, and the device serial number. The step of obtaining the device feature string by combining the manufacturer number, the product number, and the device serial number if the first preset priority condition is not met also includes: if the device attributes of the target USB camera device do not meet the first preset priority condition, and all attributes in the device attributes are missing, then the device feature string is determined based on the original device path corresponding to the target USB camera device.
[0033] Furthermore, a hash calculation is performed on the device characteristic string to obtain the device identifier. Figure 3 This diagram illustrates the generation of a device identifier. The MD5 (Message-Digest Algorithm 5) hash algorithm is used to hash the device characteristic string, and the first 12 characters of the generated hash value are extracted as the device identifier, ensuring uniqueness while facilitating display and storage. Taking the characteristic string "pci-0000:00:14.0-usb-0:10_1bcf_28c4_01.00.00" as an example, the 12-character device identifier generated by hashlib.md5(characteristic string.encode()).hexdigest()[:12] is "88cfcf82c6b0".
[0034] In this embodiment, to avoid multiple cameras with identical hardware identifiers in the system, such as cameras of the same model without serial numbers causing identifier conflicts, after obtaining the device identifier, the device identifiers of the target USB camera device are detected. Based on the detection results, duplicate USB camera devices with duplicate device identifiers are identified. A new device feature string is determined based on the device number corresponding to the duplicate USB camera device, and the process jumps to the step of hashing the device feature string until the detection results indicate that there are no duplicate USB camera devices with duplicate device identifiers. Here, the device number refers to the numeric sequence number X in / dev / videoX (i.e., the minor device number assigned by the Linux kernel to V4L2 devices), not the physical port number. That is, when two cameras of the same model happen to have the same device identifier due to missing serial numbers and after physical topology path normalization, the current system's device number X is used as an additional input (i.e., salt) to break the conflict. This device number is only valid in the current running session and is a temporary conflict resolution method, which does not affect the long-term stable identification based on the physical topology path.
[0035] Specifically, after performing hash calculation on the device feature string to obtain the device identifier, the method further includes: detecting each device identifier of the target USB camera device, and determining, based on the obtained detection results, duplicate USB camera devices with duplicate device identifiers; determining a new device feature string based on the device number corresponding to the duplicate USB camera device, and jumping to the step of performing hash calculation on the device feature string, until the obtained detection results indicate that there are no duplicate USB camera devices with duplicate device identifiers.
[0036] Step S13: Establish a mapping relationship between the device identifier of the target USB camera device and the corresponding service configuration information, and write the mapping relationship into the target configuration file.
[0037] In this embodiment, the generated device identifier is associated with the corresponding service configuration information of the device to establish a mapping relationship. The service configuration information can include exposure, contrast, alarm settings, etc., and this mapping relationship is written to the target configuration file. The mapping relationship can be persistently stored in the target configuration file in JSON format, so that the target configuration file can be automatically loaded after the system restarts, realizing persistent management of the configuration.
[0038] Step S14: When a target drift event occurs in the Linux system, obtain the USB camera device to be started that the application needs to start, determine the startup identifier corresponding to the USB camera device to be started from the target configuration file, identify each USB camera device that has completed USB bus enumeration in the Linux system as the new USB camera devices, and then jump to the step of executing the target udevadm command on each USB camera device in the Linux system to obtain the identifier of each target device; the target drift event includes Linux system restart and hot plugging / unplugging of USB camera devices.
[0039] In this embodiment, Figure 4 This diagram illustrates a dynamic device lookup process. After a Linux system reboot or camera hot-plugging / plugging, the ` / dev / videoX` device number may have changed. In this case, the process retrieves the USB camera device that the application needs to start and searches the target configuration file for its corresponding startup identifier. Simultaneously, all USB camera devices currently enumerated on the USB bus are treated as new USB camera devices, and the device identifier processing flow is re-executed. This involves re-executing the target `udevadm` command for each current USB camera device, parsing and normalizing the physical topology path, combining and hashing the paths, thus obtaining the target device identifier for each USB camera device in real time. This process also only uses the `udevadm` command to query device information, without opening the ` / dev / video` device file, therefore it does not interfere with cameras currently in use.
[0040] Step S15: Match each of the target device identifiers with the identifier to be started, and use the matching results to determine the target device path of the USB camera device to be started in the Linux system.
[0041] In this embodiment, each target device identifier is matched with the identifier to be started, and the matching result is used to determine the target device index corresponding to the USB camera device to be started. Based on the target device index, the target device path of the USB camera device to be started in the Linux system is determined. The target device index is the numerical sequence number X in / dev / videoX corresponding to the successfully matched device, and the target device path is the corresponding / dev / videoX device file path. In this way, even if the device number changes after a target drift event, the current actual target device path corresponding to the USB camera device to be started can be accurately located based on the stable device identifier, achieving dynamic device positioning.
[0042] Specifically, the step of matching each of the target device identifiers with the identifier to be started, and using the matching results to determine the target device path of the USB camera device to be started in the Linux system, includes: matching each of the target device identifiers with the identifier to be started, and using the matching results to determine the target device index corresponding to the USB camera device to be started; and determining the target device path of the USB camera device to be started in the Linux system based on the target device index.
[0043] As can be seen from the above, this application determines the target USB camera device by executing the target udevadm command on each USB camera device in the Linux system and using a preset judgment mechanism, thereby obtaining device attributes including physical topology path, manufacturer number, product number, and device serial number. Since the physical topology path is based on the physical connection relationship between the USB controller and the port, it is not affected by the system enumeration order. The physical topology path is parsed and regular expressions are used to remove dynamically changing interface number suffixes to obtain a normalized path. Then, a stable device identifier is generated by combining hardware characteristics, and a mapping relationship is established between the device identifier and the business configuration information and written into the target configuration file. When target drift events such as system restart or hot-plugging of USB camera devices occur, the target device identifiers are recalculated and matched with the identifier to be started, so as to accurately locate the target device path of the USB camera device to be started in the system. In this way, the configuration can take effect automatically after system restart or hot-plugging without manual reconfiguration, the stability of device identification is significantly improved, and the identification process only queries device information through system commands, without opening the camera device, avoiding interference with the camera in use and ensuring the continuity of the production system.
[0044] As can be seen from the above embodiments, this application realizes the dynamic positioning of the camera device based on the device unique identifier determined by the physical topology path of the USB camera device. Therefore, the process of realizing the dynamic positioning of the camera device based on the device unique identifier determined by the physical topology path of the USB camera device is described.
[0045] Combination Figure 5 and Figure 6 As shown, this embodiment of the invention discloses a specific path positioning method for a camera device, including: This embodiment includes an information acquisition module, a path parsing module, an identifier generation module, a configuration management module, and a dynamic lookup module. First, the information acquisition module uses the udevadm tool to traverse the camera device nodes corresponding to / dev / video 0-19 to collect the device attributes of the USB camera devices. The path parsing module parses the physical topology path in the device attributes to obtain the PCI controller location identifier, USB port path identifier, and interface number suffix. Regular expressions are used to match and remove the interface number suffix to obtain a normalized path. The identifier generation module combines the normalized path, manufacturer ID, product ID, and device serial number to obtain a device feature string. When the physical topology path is available, the normalized path, manufacturer ID, product ID, and device serial number are concatenated using underscores to form the feature string; when the physical topology path is unavailable, the combination of manufacturer ID, product ID, and device serial number is used instead; when all the above hardware information is missing, a hash calculation is performed directly on the / dev / videoX device path as a final backup. After generating identifiers for all devices, duplicate detection is performed on all identifiers. When there are multiple cameras of the same model without serial numbers in the system, there may be a situation where the identifiers are duplicated.
[0046] Understandably, the configuration management module associates the generated device identifier with the corresponding business configuration information and writes it into the target configuration file. When the Linux system experiences a target drift event such as a restart or hot-plugging of the camera, it obtains the USB camera device to be started that the application needs to start, determines the startup identifier corresponding to the USB camera device to be started from the target configuration file, identifies each USB camera device in the Linux system that has completed USB bus enumeration as the new USB camera devices, and then jumps to the step of executing the target udevadm command on each USB camera device in the Linux system to obtain the target device identifier.
[0047] Furthermore, all target device identifiers are traversed and matched one by one with the identifier to be launched. Upon successful matching, the target device index of the corresponding device is obtained, and the complete target device path is obtained by concatenating these paths. This target device path is then used to dynamically locate the USB camera device to be launched. The application can then directly open the corresponding camera through this path without manual reconfiguration.
[0048] As can be seen from the above, the identification method based on physical topology path in this application is not affected by the system enumeration order, and the configuration takes effect automatically after the Linux system restarts without manual intervention; moreover, it does not require modification of the Linux kernel, USB driver or system configuration, and does not require opening the camera device during the dynamic search process, so as not to interrupt the ongoing video acquisition or inference tasks, thus ensuring the continuity of the production system.
[0049] Accordingly, see Figure 7 As shown, this application also provides a path positioning device for a camera device, comprising: The device attribute acquisition module 11 is used to execute the target udevadm command on each USB camera device in the Linux system, determine the target USB camera device from the USB camera devices based on the obtained command execution result and using a preset judgment mechanism, and obtain the device attributes corresponding to the target USB camera device; the device attributes include physical topology path, manufacturer number, product number and device serial number; The hash calculation module 12 is used to parse the physical topology path in the device attributes to obtain the corresponding parsing result, and to perform normalization processing based on the parsing result using regular expressions to obtain a normalized path. The normalized path, the manufacturer number, the product number and the device serial number are combined to obtain a device feature string, and the device feature string is hashed to obtain a device identifier. The mapping relationship writing module 13 is used to establish a mapping relationship between the device identifier of the target USB camera device and the corresponding service configuration information, and write the mapping relationship into the target configuration file; The target identifier determination module 14 is used to, when a target drift event occurs in the Linux system, obtain the USB camera device to be started that the application needs to start, determine the startup identifier corresponding to the USB camera device to be started from the target configuration file, identify each USB camera device in the Linux system that has completed USB bus enumeration as the new USB camera devices, and then jump to the step of executing the target udevadm command on each USB camera device in the Linux system to obtain the target device identifier; the target drift event includes Linux system restart and hot-plugging of USB camera devices; The target path determination module 15 is used to match each of the target device identifiers with the identifier to be started, and to determine the target device path of the USB camera device to be started in the Linux system using the matching results.
[0050] In some specific embodiments, the device attribute acquisition module 11 may specifically include: The device rejection unit is used to execute the target udevadm command on each USB camera device in the Linux system to obtain the corresponding device information, determine whether there is a manufacturer number in each device information, and reject the USB camera devices that do not have a manufacturer number in the device information based on the obtained judgment result and each USB camera device to obtain the rejected camera devices. The target device determination unit is configured to determine the removed camera device as a target USB camera device if the field corresponding to the manufacturer number of the removed camera device contains a target USB substring.
[0051] In some specific embodiments, the hash calculation module 12 may specifically include: The path resolution unit is used to parse the physical topology path in the device attributes to obtain the PCI controller location identifier, USB port path identifier and interface number suffix; The suffix removal unit is used to match and remove the suffixes of the interface number using regular expressions to obtain a normalized path.
[0052] In some specific embodiments, the hash calculation module 12 may specifically include: A device attribute determination unit is used to determine whether the device attributes of the target USB camera device meet a first preset priority condition; the first preset priority condition is that the physical topology path in the device attributes meets a preset availability condition. The first serial number combination unit is used to combine the normalized path, the manufacturer number, the product number and the device serial number to obtain a device feature string if the first preset priority condition is met. The second serial number combination unit is used to combine the manufacturer number, the product number and the device serial number to obtain a device feature string if the first preset priority condition is not met.
[0053] In some specific embodiments, the path positioning device of the camera equipment may further include: The attribute missing unit is used to determine the device feature string based on the original device path corresponding to the target USB camera device if the device attributes of the target USB camera device do not meet the first preset priority condition and all attributes in the device attributes are missing.
[0054] In some specific embodiments, the path positioning device of the camera equipment may further include: The duplicate device determination unit is used to detect each device identifier of the target USB camera device and determine duplicate USB camera devices with duplicate device identifiers based on the detection results. The new string determination unit is used to determine a new device feature string based on the device number corresponding to the duplicate USB camera device, and then jump to the step of hashing the device feature string until the detection result indicates that there is no duplicate USB camera device with duplicate device identifier.
[0055] In some specific embodiments, the target path determination module 15 may specifically include: The target index determination unit is used to match each of the target device identifiers with the identifier to be started, and to determine the target device index corresponding to the USB camera device to be started using the matching result; The target path determination unit is used to determine the target device path of the USB camera device to be started in the Linux system based on the target device index.
[0056] Furthermore, embodiments of this application also disclose an electronic device, Figure 8 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the path positioning method of the camera device disclosed in any of the foregoing embodiments. Furthermore, the electronic device 20 in this embodiment may specifically be a computer.
[0057] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0058] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon can include operating system 221, computer program 222, etc., and the storage method can be temporary storage or permanent storage.
[0059] The operating system 221 is used to manage and control the various hardware devices on the electronic device 20 and the computer program 222, which may be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program capable of performing the path positioning method of the camera device executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include a computer program capable of performing other specific tasks.
[0060] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned path positioning method for a camera device. Specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.
[0061] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.
[0062] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0063] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0064] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0065] The technical solutions provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A path positioning method for a camera device, characterized in that, include: The target udevadm command is executed on each USB camera device in the Linux system. Based on the command execution result and a preset determination mechanism, the target USB camera device is determined from the USB camera devices, and the device attributes corresponding to the target USB camera device are obtained. The device attributes include physical topology path, manufacturer number, product number, and device serial number. The physical topology path in the device attributes is parsed to obtain the corresponding parsing result. Based on the parsing result, it is normalized using regular expressions to obtain a normalized path. The normalized path, the manufacturer number, the product number, and the device serial number are combined to obtain a device feature string. The device feature string is hashed to obtain a device identifier. Establish a mapping relationship between the device identifier of the target USB camera device and the corresponding service configuration information, and write the mapping relationship into the target configuration file; When a target drift event occurs in the Linux system, the system obtains the USB camera devices that the application needs to start, determines the startup identifier corresponding to the USB camera device from the target configuration file, identifies the USB camera devices that have completed USB bus enumeration in the Linux system as the new USB camera devices, and then jumps to the step of executing the target udevadm command on each USB camera device in the Linux system to obtain the target device identifier; the target drift event includes Linux system restart and hot-plugging of USB camera devices; The target device identifier is matched with the identifier to be started, and the target device path of the USB camera device to be started in the Linux system is determined by using the matching results.
2. The path positioning method for a camera device according to claim 1, characterized in that, The step of executing the target udevadm command on each USB camera device in the Linux system, and determining the target USB camera device from the USB camera devices based on the command execution results and a preset determination mechanism, includes: The target udevadm command is executed on each USB camera device in the Linux system to obtain the corresponding device information. It is determined whether there is a manufacturer number in each device information. Based on the obtained determination result and each USB camera device, the USB camera devices that do not have a manufacturer number in the device information are removed to obtain the removed camera devices. If the field corresponding to the manufacturer number of the removed camera device contains the target USB substring, then the removed camera device is identified as the target USB camera device.
3. The path positioning method for a camera device according to claim 1, characterized in that, The process of parsing the physical topology path in the device attributes to obtain the corresponding parsing result, and then performing normalization processing based on the parsing result using regular expressions to obtain the normalized path, includes: The physical topology path in the device attributes is parsed to obtain the PCI controller location identifier, USB port path identifier, and interface number suffix; Regular expressions are used to match and remove the suffixes of the interface number to obtain a normalized path.
4. The path positioning method for a camera device according to claim 1, characterized in that, The process of combining the normalized path, the manufacturer's ID, the product ID, and the device serial number to obtain a device characteristic string includes: Determine whether the device attributes of the target USB camera device meet a first preset priority condition; the first preset priority condition is that the physical topology path in the device attributes meets a preset availability condition. If the first preset priority condition is met, the device feature string is obtained by combining the normalized path, the manufacturer number, the product number, and the device serial number. If the first preset priority condition is not met, the device feature string is obtained by combining the manufacturer number, the product number, and the device serial number.
5. The path positioning method for a camera device according to claim 4, characterized in that, If the first preset priority condition is not met, the method of combining the manufacturer number, the product number, and the device serial number to obtain a device feature string further includes: If the device attributes of the target USB camera device do not meet the first preset priority condition, and all attributes in the device attributes are missing, then the device feature string is determined based on the original device path corresponding to the target USB camera device.
6. The path positioning method for a camera device according to claim 1, characterized in that, After performing a hash calculation on the device feature string to obtain the device identifier, the method further includes: The device identifiers of the target USB camera device are detected, and based on the detection results, duplicate USB camera devices with duplicate device identifiers are identified. A new device feature string is determined based on the device number corresponding to the duplicate USB camera device, and the process jumps to the step of hashing the device feature string until the detection result indicates that there is no duplicate USB camera device with duplicate device identifier.
7. The path positioning method for a camera device according to claim 1, characterized in that, The step of matching each of the target device identifiers with the identifier to be started, and using the matching results to determine the target device path of the USB camera device to be started in the Linux system, includes: The target device identifier is matched with the identifier to be started, and the target device index corresponding to the USB camera device to be started is determined by using the matching result; The target device path of the USB camera device to be started in the Linux system is determined based on the target device index.
8. A path positioning device for a camera device, characterized in that, include: The device attribute acquisition module is used to execute the target udevadm command on each USB camera device in the Linux system, determine the target USB camera device from the USB camera devices based on the command execution result and a preset judgment mechanism, and obtain the device attributes corresponding to the target USB camera device; the device attributes include physical topology path, manufacturer number, product number and device serial number; The hash calculation module is used to parse the physical topology path in the device attributes to obtain the corresponding parsing result, and to perform normalization processing based on the parsing result using regular expressions to obtain a normalized path. The normalized path, the manufacturer number, the product number and the device serial number are combined to obtain a device feature string, and the device feature string is hashed to obtain a device identifier. The mapping relationship writing module is used to establish a mapping relationship between the device identifier of the target USB camera device and the corresponding service configuration information, and write the mapping relationship into the target configuration file; The target identifier determination module is used to, when a target drift event occurs in the Linux system, obtain the USB camera device to be started by the application, determine the startup identifier corresponding to the USB camera device to be started from the target configuration file, identify the USB camera devices that have completed USB bus enumeration in the Linux system as the new USB camera devices, and then jump to the step of executing the target udevadm command on each USB camera device in the Linux system to obtain the target device identifier; the target drift event includes Linux system restart and hot-plugging of USB camera devices; The target path determination module is used to match each of the target device identifiers with the identifier to be started, and use the matching results to determine the target device path of the USB camera device to be started in the Linux system.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the path positioning method of the camera device as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, Used to store a computer program, wherein the computer program, when executed by a processor, implements the path positioning method of the camera device as described in any one of claims 1 to 7.
