An image format conversion method and device, an electronic device, and a storage medium
By acquiring accelerated images and performing image format conversion after the processor frequency reaches a preset frequency, the problem of excessively long first frame image processing time is solved, achieving balanced image format conversion efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGZHOU HIKROBOT TECH CO LTD
- Filing Date
- 2023-01-12
- Publication Date
- 2026-08-04
AI Technical Summary
In CPUs that support Turbo Boost technology, the format conversion time for the first frame is significantly longer than that for subsequent frames, resulting in uneven computational efficiency.
The system acquires accelerated images and triggers the processor to perform format conversion. It detects the processor frequency and acquires the video to be processed after reaching the preset frequency, ensuring that all image frames are converted at the same frequency.
By triggering the processor to perform format conversion on the accelerated image when the image format conversion instruction is obtained, the processor frequency is accelerated to a preset frequency, thereby reducing the format conversion time of the first frame image and achieving stable image format conversion.
Smart Images

Figure CN116156087B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image format conversion technology, and in particular to an image format conversion method, apparatus, electronic device, and storage medium. Background Technology
[0002] Machine vision systems utilize machines to perform various measurements and judgments, replacing human eyes. Industrial cameras and capture cards are crucial components of machine vision systems. These devices typically store video images and can also specify video image formats for rendering, necessitating the conversion of video images between different color formats.
[0003] For CPUs (Central Processing Units) that support Turbo Boost technology, during the color format conversion of images, the CPU accelerates to a certain frequency when processing the first frame of the image to achieve higher computational efficiency. Subsequent images are then processed based on this frequency for format conversion. This results in the format conversion time for the first frame being significantly longer than that for subsequent frames. Summary of the Invention
[0004] The purpose of this application is to provide an image format conversion method, apparatus, electronic device, and storage medium to reduce the time consumed in converting the format of the first frame image. The specific technical solution is as follows:
[0005] In a first aspect, embodiments of this application provide an image format conversion method, the method comprising:
[0006] If an image format conversion instruction is received, an accelerated image is obtained;
[0007] The processor is triggered to perform format conversion on the accelerated image, wherein the amount of processing required for the format conversion of the accelerated image is not less than the amount of processing required for the format conversion of the first frame image of the video to be processed;
[0008] The frequency of the processor is detected, and when the frequency of the processor is accelerated to a preset frequency, the video to be processed is acquired, and the format of each frame of the video to be processed is converted.
[0009] Optionally, the step of acquiring the accelerated image and triggering the processor to perform format conversion on the accelerated image includes:
[0010] Start the first thread and obtain the accelerated image through the first thread;
[0011] The first thread triggers the processor to perform format conversion on the accelerated image.
[0012] Optionally, the step of detecting the frequency of the processor and acquiring the video to be processed when the processor frequency is accelerated to a preset frequency includes:
[0013] Start a second thread, and use the second thread to detect whether the processor frequency has reached the preset frequency;
[0014] When the second thread detects that the processor frequency has reached the preset frequency, it acquires the video to be processed.
[0015] Optionally, prior to the step of acquiring the accelerated image, the method further includes:
[0016] Obtain the image parameters of the first frame of the video to be processed;
[0017] The step of acquiring the accelerated image includes:
[0018] Based on the image parameters of the first frame image, an accelerated image is determined from pre-stored candidate images; or,
[0019] Based on the width and height of the first frame image, the width and height of the accelerated image are determined respectively; the pixel values of each pixel point of the accelerated image are randomly written to generate the accelerated image, wherein the width of the accelerated image is not less than the width of the first frame image, and the height of the accelerated image is not less than the height of the first frame image.
[0020] Optionally, the step of acquiring the accelerated image includes:
[0021] The image acquired by the target image acquisition device is obtained as an accelerated image, wherein the target image acquisition device is the acquisition device that acquires the video to be processed.
[0022] Optionally, before the step of acquiring the accelerated image, the method further includes:
[0023] Get the processor model;
[0024] Based on the processor model, determine whether the processor supports frequency acceleration;
[0025] If it is determined that the processor supports frequency acceleration, the step of acquiring the accelerated image is performed.
[0026] Optionally, the format is converted to a color format conversion;
[0027] Prior to the step of acquiring the accelerated image, the method further includes:
[0028] Obtain the source and target color formats of the video to be processed;
[0029] If the source color format is different from the target color format, an image format conversion instruction is obtained.
[0030] Secondly, embodiments of this application provide an image format conversion apparatus, the apparatus comprising:
[0031] The accelerated image acquisition module is used to acquire accelerated images when an image format conversion instruction is received;
[0032] The first conversion module is used to trigger the processor to perform format conversion on the accelerated image, wherein the amount of processing required for the format conversion of the accelerated image is not less than the amount of processing required for the format conversion of the first frame image of the video to be processed.
[0033] The second conversion module is used to detect the frequency of the processor, and when the frequency of the processor is accelerated to a preset frequency, to acquire the video to be processed and to convert the format of each frame of the video to be processed.
[0034] Optionally, the accelerated image acquisition module includes:
[0035] The accelerated image acquisition submodule is used to start the first thread and acquire accelerated images through the first thread.
[0036] The first conversion module includes:
[0037] The first conversion submodule is used to trigger the processor to perform format conversion on the accelerated image through the first thread.
[0038] Optionally, the second conversion module includes:
[0039] The preset frequency detection submodule is used to start a second thread and detect whether the processor frequency has reached the preset frequency.
[0040] The video to be processed acquisition submodule is used to acquire the video to be processed when the second thread detects that the frequency of the processor has reached the preset frequency.
[0041] Optionally, the device further includes:
[0042] The image parameter acquisition module is used to acquire the image parameters of the first frame of the video to be processed before the step of acquiring the accelerated image;
[0043] The accelerated image acquisition module includes:
[0044] The first acquisition submodule is used to determine an accelerated image from pre-stored candidate images based on the image parameters of the first frame image; or,
[0045] The accelerated image is generated by determining the width and height of the accelerated image based on the width and height of the first frame image, respectively, and by randomly writing the pixel values of each pixel in the accelerated image, wherein the width of the accelerated image is not less than the width of the first frame image, and the height of the accelerated image is not less than the height of the first frame image.
[0046] Optionally, the accelerated image acquisition module includes:
[0047] The second acquisition submodule is used to acquire the image acquired by the target image acquisition device as an accelerated image, wherein the target image acquisition device is the acquisition device that acquires the video to be processed.
[0048] Optionally, the device further includes:
[0049] The model acquisition module is used to acquire the processor model before the step of acquiring the accelerated image;
[0050] A frequency acceleration determination module is used to determine whether the processor supports frequency acceleration based on the processor's model.
[0051] An accelerated image acquisition module is used to perform the step of acquiring an accelerated image when it is determined that the processor supports frequency acceleration.
[0052] Optionally, the format is converted to a color format conversion; the apparatus further includes:
[0053] The format acquisition module is used to acquire the source color format and target color format of the video to be processed before the step of acquiring the accelerated image;
[0054] The conversion instruction acquisition module is used to determine and acquire an image format conversion instruction when the source color format is different from the target color format.
[0055] Thirdly, embodiments of this application provide an electronic device, including:
[0056] Memory, used to store computer programs;
[0057] When a processor executes a program stored in memory, it implements any of the methods described in the first aspect above.
[0058] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements any of the methods described in the first aspect above.
[0059] Beneficial effects of the embodiments in this application:
[0060] In the solution provided in this application embodiment, the electronic device can acquire an accelerated image upon receiving an image format conversion instruction, triggering the processor to perform format conversion on the accelerated image. The processing power required for format conversion of the accelerated image is not less than the processing power required for format conversion of the first frame of the video to be processed. The processor frequency is detected, and when the processor frequency is accelerated to a preset frequency, the video to be processed is acquired, and format conversion is performed on each frame of the video. Since the processor can be triggered to perform format conversion on the accelerated image upon receiving an image format conversion instruction, causing the processor frequency to accelerate to a preset frequency, the first frame and subsequent frames of the video to be processed can be converted at the preset frequency, thus reducing the time consumed by format conversion of the first frame. Of course, implementing any product or method of this application does not necessarily require achieving all the advantages described above simultaneously. Attached Figure Description
[0061] To more clearly illustrate the technical solutions in the embodiments of this application 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 some embodiments of this application. For those skilled in the art, other embodiments can be obtained based on these drawings.
[0062] Figure 1 A flowchart illustrating an image format conversion method provided in an embodiment of this application;
[0063] Figure 2 Based on Figure 1 The illustrated embodiment is a specific flowchart for accelerating image format conversion;
[0064] Figure 3 for Figure 1 A specific flowchart of step S103 in the illustrated embodiment;
[0065] Figure 4 Based on Figure 1 The illustrated embodiment is a flowchart for determining whether a processor supports frequency acceleration;
[0066] Figure 5 This is a specific flowchart of an image format conversion method provided in an embodiment of this application;
[0067] Figure 6 This is a schematic diagram of the structure of an image format conversion device provided in an embodiment of this application;
[0068] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0069] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art based on this application are within the scope of protection of this application.
[0070] To reduce the time spent on converting the format of the first frame image, embodiments of this application provide an image format conversion method, apparatus, electronic device, computer-readable storage medium, and computer program product. The image format conversion method provided by embodiments of this application will be introduced first.
[0071] The image format conversion method provided in this application embodiment can be applied to any electronic device that requires image format conversion, such as an image processing device, etc., without specific limitation. For clarity, it will be referred to as an electronic device below.
[0072] like Figure 1 As shown, an image format conversion method includes:
[0073] S101, upon receiving an image format conversion instruction, acquire the accelerated image;
[0074] S102, triggering the processor to perform format conversion on the accelerated image;
[0075] The amount of processing required for the format conversion of the accelerated image is no less than the amount of processing required for the format conversion of the first frame of the video to be processed.
[0076] S103, detect the frequency of the processor, and when the frequency of the processor is accelerated to a preset frequency, acquire the video to be processed, and perform format conversion on each frame of the video to be processed.
[0077] As can be seen, in the solution provided in this application embodiment, the electronic device can acquire an accelerated image upon receiving an image format conversion instruction, triggering the processor to perform format conversion on the accelerated image. The processing power required for format conversion of the accelerated image is not less than the processing power required for format conversion of the first frame of the video to be processed. The processor frequency is detected, and when the processor frequency is accelerated to a preset frequency, the video to be processed is acquired, and format conversion is performed on each frame of the video to be processed. Since the processor can be triggered to perform format conversion on the accelerated image upon receiving an image format conversion instruction, causing the processor frequency to accelerate to a preset frequency, the first frame and subsequent frames of the video to be processed can be converted at the preset frequency, thus reducing the time consumed by format conversion of the first frame.
[0078] Machine vision uses machines to replace human eyes for measurement and judgment. A machine vision system can automatically receive and process images of a real object through optical devices and non-contact sensors to obtain the required information or to control the movement of the machine.
[0079] For example, a machine vision system generally consists of an optical system (light source, lens, industrial camera), an image acquisition unit (image acquisition device, acquisition card), an image processing unit, an actuator, and a human-machine interface. Among these, the industrial camera and acquisition card are important components of the machine vision system, capable of storing video images and specifying video image formats to convert video images to different color formats.
[0080] If the processor supports Turbo Boost technology, when converting video images to different color formats, the processor will accelerate to a certain frequency during the processing of the first frame to achieve higher computational efficiency. Subsequent frames can then be converted based on this frequency. However, this results in the format conversion time for the first frame being significantly longer than that for subsequent frames. Turbo Boost refers to a technology where, upon starting a running program, the processor automatically accelerates to an appropriate frequency, increasing its original running speed to ensure smooth program operation. Therefore, to reduce the time spent on format conversion of the first frame, this application provides an image format conversion method.
[0081] In step S101, when the electronic device receives an image format conversion instruction, it can acquire an accelerated image.
[0082] Image format refers to the format in which image data is stored. It can reflect information such as image size, resolution, and image mode. Image formats can include RAW, BMP, TIFF, JPEG, PNG, etc. Format conversion can be a conversion of the encapsulation format, such as encapsulating the source data MONO8 into BMP, or a conversion of the color format, such as converting from RGB (Red Green Blue) format to Lab (Luminance Chrominance Chroma) format, or converting from one 16-bit RGB format to another 32-bit RGB format. No specific limitation is made here.
[0083] Since processors generally support Turbo Boost technology, when users perform format conversion on the video images being processed, they will find that the format conversion time for the first frame is significantly longer than that for subsequent frames. Therefore, in order to ensure that the format conversion of the first frame and subsequent frames can be performed at a certain processor frequency, a pseudo-image similar to the first frame can be obtained as an acceleration image before format conversion of each frame. The processor can then perform format conversion on this acceleration image first. In this way, after the processor frequency reaches a certain frequency, the format conversion of each frame of the video being processed can be performed, thus enabling stable format conversion of each frame of the video being processed.
[0084] The accelerated image can be a pre-stored alternative image, an image randomly generated based on the width and height of the first frame image, or an image captured by an image acquisition device; no specific limitation is made here.
[0085] In one implementation, the user can set the source and target formats of an image to perform format conversion on the image acquired by the image acquisition device. Upon receiving the image format conversion instruction from the user, the electronic device can acquire the accelerated image. The source and target formats can include encapsulation formats, color formats, etc., and are not specifically limited here.
[0086] For example, both the industrial camera and the acquisition card have an SDK (Software Development Kit). The SDK provides a set of encapsulated APIs (Application Programming Interfaces), through which the parameters of the industrial camera can be configured, and the media data of the industrial camera can be acquired through corresponding protocol processes. When users perform various format or color space conversions on the acquired images, the SDK provides corresponding interfaces to configure the format parameters of the source data and the target data. Simultaneously, the SDK provides corresponding conversion interfaces to complete the data conversion when the acquired streaming data is input into the conversion interface.
[0087] For example, in a machine vision system connected to an industrial camera, the industrial camera can capture images. The user sets the industrial camera so that the source format of the images captured by the industrial camera is BMP. The user needs to convert the image format and sets the target format of the image to JPEG. Then, the electronic device can obtain the image format conversion instruction sent by the user and then obtain the accelerated image from the pre-stored candidate images.
[0088] Next, in step S102, the electronic device can trigger the processor to perform format conversion on the accelerated image.
[0089] In one implementation, the electronic device can activate a thread to accelerate the processor's frequency. Specifically, this thread can acquire accelerated images and trigger the processor to perform format conversion on the accelerated images.
[0090] Since the purpose of format conversion for accelerated images is to ensure that the processor frequency reaches the frequency required for format conversion of the first frame of the video to be processed, the accelerated image and the first frame of the video to be processed should be similar. Furthermore, the processing power required for format conversion of the accelerated image should be no less than that required for format conversion of the first frame of the video to be processed.
[0091] For example, if the source format of an image captured by an industrial camera is 16-bit RGB, and the target format for image format conversion is 32-bit RGB, and the size of the first frame of the video to be processed is 512k, then the size of the accelerated image should be no less than 512k. When the electronic device receives the image format conversion instruction, it can start a thread to accelerate the processor frequency, acquire the accelerated image, and trigger the processor to perform format conversion on the accelerated image through this thread, that is, convert the accelerated image from 16-bit RGB format to 32-bit RGB format.
[0092] During the process of converting the accelerated image into a format, the processor also automatically accelerates its frequency. In step S103, the electronic device can detect the frequency of the processor and, when the frequency of the processor is accelerated to a preset frequency, acquire the video to be processed, and then convert the format of each frame of the video to be processed.
[0093] The preset frequency can be either a frequency that increases the processor's operating speed by 10% or a frequency that increases the processor's operating speed by 20%, and no specific limit is set here.
[0094] In one implementation, the electronic device can activate a thread for detecting the processor frequency. Specifically, when the processor accelerates its frequency, this thread can detect whether the processor frequency has reached a preset frequency at preset intervals. If the processor frequency reaches the preset frequency, the user is notified that the processor can perform format conversion on each frame of the video to be processed. In this way, the electronic device can acquire the video to be processed and perform stable format conversion on each frame of the video.
[0095] For example, with a preset frequency of F1 and a preset interval of T1, when an electronic device receives an image format conversion instruction, it can start a thread to detect the processor frequency. During the process of the processor accelerating the frequency, the thread to detect the processor frequency can periodically detect whether the processor frequency has reached the preset frequency F1 according to the preset interval of T1. When the processor frequency accelerates to the preset frequency F1, the user is informed that the processor can process the video to be processed, thereby obtaining the video to be processed and converting the format of each frame of the video to be processed.
[0096] In this embodiment, when the electronic device receives an image format conversion instruction, it can trigger the processor to perform format conversion on the accelerated image, thereby accelerating the processor frequency to a preset frequency. In this way, when converting the format of each frame of the video to be processed, the first frame and subsequent frames can be converted at the preset frequency. Therefore, the format conversion time of the first frame can be reduced, and stable format conversion can be performed on each frame of the video to be processed.
[0097] As one implementation method of this application, such as Figure 2 As shown, the steps described above for acquiring an accelerated image and triggering the processor to perform format conversion on the accelerated image may include:
[0098] S201, Start the first thread and obtain the accelerated image through the first thread;
[0099] S202, the processor is triggered to perform format conversion on the accelerated image through the first thread.
[0100] When an electronic device receives an image format conversion instruction, in order to accelerate the processor frequency to a preset frequency before converting the format of each frame of the video to be processed, a separate thread for accelerating the processor frequency can be started. In this way, when the processor frequency reaches the preset frequency, the format conversion of each frame of the video to be processed can be performed in a timely manner.
[0101] In one implementation, the electronic device can activate a first thread to accelerate the processor's frequency. The electronic device can then acquire accelerated images through this first thread.
[0102] After the first thread obtains the accelerated image, it can trigger the processor to perform format conversion on the accelerated image so that the processor frequency can reach the frequency required for the processor to perform format conversion on the first frame of the video to be processed, i.e., the preset frequency.
[0103] In one implementation, the first thread can trigger the processor to perform format conversion on the accelerated image through the corresponding conversion interface provided by the SDK.
[0104] For example, the source format of images acquired by an industrial camera is RGB format, and the target format for image format conversion is YUV format. When the electronic device receives the image format conversion instruction, it can start the first thread to acquire the accelerated image. After acquiring the accelerated image, the first thread can trigger the processor to convert the accelerated image to YUV format through the RGB to YUV format interface provided by the SDK, that is, convert the accelerated image from RGB format to YUV format.
[0105] As can be seen, in this embodiment, the electronic device can activate a first thread to acquire accelerated images and trigger the processor to perform format conversion on the accelerated images. Therefore, the processor can accelerate its frequency by performing format conversion on the accelerated images. When the processor frequency is accelerated to a preset frequency, the format conversion of the first frame and subsequent frames of the video to be processed can be performed, thereby reducing the time consumed by the format conversion of the first frame.
[0106] As one implementation method of this application, such as Figure 3 As shown, the step of detecting the frequency of the processor and acquiring the video to be processed when the processor frequency is accelerated to a preset frequency may include:
[0107] S301, Start the second thread, and use the second thread to detect whether the processor frequency has reached the preset frequency;
[0108] S302, when the second thread detects that the frequency of the processor has reached the preset frequency, the video to be processed is acquired.
[0109] Since the processor is accelerating the frequency while converting the format of the accelerated image, in order to convert the format of each frame of the video to be processed in a timely manner when the processor frequency reaches the preset frequency, the electronic device can periodically detect the processor frequency.
[0110] In one implementation, the electronic device can activate a second thread to detect whether the processor frequency has reached a preset frequency. Specifically, the second thread can detect whether the processor frequency has reached the preset frequency at preset intervals.
[0111] When the second thread detects that the processor frequency has reached the preset frequency, it informs the user that the processor can perform format conversion on each frame of the video to be processed. In this way, the electronic device can acquire the video to be processed and perform stable format conversion on each frame of the video to be processed.
[0112] For example, with a preset frequency of F and a preset interval of T, when an electronic device receives an image format conversion instruction, it can start a first thread and a second thread. The first thread accelerates the processor frequency, and the second thread can detect whether the processor frequency has reached the preset frequency F according to the preset interval of T. When the processor frequency is accelerated to the preset frequency F, the user can be informed that the processor can process the video to be processed, thereby obtaining the video to be processed and converting the format of each frame of the video to be processed.
[0113] As can be seen, in this embodiment, the electronic device activates a second thread to detect whether the processor frequency has reached a preset frequency. If the second thread detects that the processor frequency has reached the preset frequency, it acquires the video to be processed. Since the electronic device can acquire the video to be processed when the processor frequency reaches the preset frequency, the processor can perform format conversion on each frame of the video. This means that the format conversion of the first frame and subsequent frames can be performed while the processor is at the preset frequency, thus reducing the time spent on format conversion of the first frame.
[0114] As one embodiment of this application, before the step of obtaining the accelerated image described above, the method may further include:
[0115] Obtain the image parameters of the first frame of the video to be processed.
[0116] Since electronic devices acquire accelerated images for format conversion, enabling the processor to reach the frequency required for format conversion of the first frame of the video to be processed, the acquired accelerated image should be similar to the first frame of the video. Therefore, the accelerated image can be obtained based on the image parameters of the first frame of the video.
[0117] Before acquiring the accelerated image, the electronic device can obtain the image parameters of the first frame of the video to be processed. These image parameters refer to the numerical information of the image, which may include resolution, color format, size, width, and height, etc., but are not specifically limited here.
[0118] In one implementation, the image acquisition device is configured with image parameters of the video to be acquired and processed. Then, the electronic device can obtain the image parameters of the first frame of the video to be processed from the image acquisition device.
[0119] For example, a machine vision system is connected to multiple industrial cameras, namely industrial camera 1, industrial camera 2 and industrial camera 3. The video to be processed is captured by industrial camera 3. Then, before the electronic device acquires the accelerated image, the image parameters of the first frame of the video to be processed can be obtained from industrial camera 3.
[0120] The steps for obtaining the accelerated image described above may include:
[0121] Based on the image parameters of the first frame image, an accelerated image is determined from pre-stored candidate images; or,
[0122] Based on the width and height of the first frame image, the width and height of the accelerated image are determined respectively; the pixel values of each pixel point of the accelerated image are randomly written to generate the accelerated image, wherein the width of the accelerated image is not less than the width of the first frame image, and the height of the accelerated image is not less than the height of the first frame image.
[0123] After obtaining the image parameters of the first frame of the video to be processed, the electronic device can obtain an accelerated image based on these image parameters.
[0124] In one implementation, the electronic device can determine the accelerated image from a pre-stored pool of candidate images based on the image parameters of the first frame image. The candidate images can be pre-stored in a folder within the SDK or in a preset database; no specific limitation is made here.
[0125] Since the image parameters of the first frame image can include resolution, color format, size, width, and height, the electronic device can determine an accelerated image from a pre-stored pool of candidate images based on at least one of the image parameters of the first frame image. For example, an image with the same resolution and color format as the first frame image can be determined from the pre-stored pool of candidate images; alternatively, an image with the same width, height, and resolution as the first frame image can be determined from the pre-stored pool of candidate images, thereby determining the accelerated image.
[0126] For example, the image parameters of the first frame image include resolution A, color format B, size C, width W, and height H. The candidate images include P1, P2, and P3. The image parameters of P1 are resolution A, color format B, size C1, width W, and height H, respectively. The image parameters of P2 are resolution A2, color format B, size C, width W, and height H, respectively. The image parameters of P3 are resolution A3, color format B3, size C, width W3, and height H3, respectively. The electronic device can determine the image with the same resolution A and color format B as the first frame image from the pre-stored candidate images based on the resolution A and color format B of the first frame image, and then determine the accelerated image as P1.
[0127] In one implementation, the electronic device can determine the width and height of the accelerated image based on the width and height of the first frame image, and then randomly write the pixel values of each pixel in the accelerated image to generate the accelerated image. The width of the accelerated image is not less than the width of the first frame image, and the height of the accelerated image is not less than the height of the first frame image.
[0128] In other words, in order to obtain an accelerated image that is similar to the first frame of the video to be processed, the accelerated image can be generated by imitating the first frame. The electronic device can determine the width and height of the accelerated image according to the width and height of the first frame. After determining the width and height of the accelerated image, the pixel values of each pixel in the accelerated image can be written continuously until the processing volume required for the format conversion of the accelerated image is not less than the processing volume required for the format conversion of the first frame of the video to be processed.
[0129] For example, if the width of the first frame image is W1 and the height is H1, then the electronic device can determine that the width of the accelerated image is W1 and the height is H1, and then randomly write the pixels of each pixel in the accelerated image to generate the accelerated image. Alternatively, the electronic device can determine that the width of the accelerated image is W2 and the height is H2, where W2 is greater than W1 and H2 is greater than H1, and then randomly write the pixels of each pixel in the accelerated image to generate the accelerated image.
[0130] As can be seen, in this embodiment, the electronic device can obtain the image parameters of the first frame of the video to be processed, and determine the accelerated image from the pre-stored candidate images based on the image parameters of the first frame, or determine the width and height of the accelerated image based on the width and height of the first frame, and randomly write the pixel values of each pixel of the accelerated image to generate the accelerated image. The width of the accelerated image is not less than the width of the first frame, and the height of the accelerated image is not less than the height of the first frame. Since the accelerated image is obtained based on the image parameters of the first frame, the processing power required for the format conversion of the accelerated image is not less than the processing power required for the format conversion of the first frame of the video to be processed. Therefore, when the processor performs format conversion on the accelerated image, the frequency can be accelerated to a preset frequency. Consequently, when performing format conversion on each frame of the video to be processed, both the first frame and subsequent frames can be converted at the preset frequency, reducing the time consumed by the format conversion of the first frame.
[0131] As one embodiment of this application, the above-described step of obtaining an accelerated image may include:
[0132] The image acquired by the target image acquisition device is obtained as an accelerated image, wherein the target image acquisition device is the acquisition device that acquires the video to be processed.
[0133] Since the image acquisition device is configured with the image parameters of the video to be acquired and processed, the electronic device can obtain any image acquired by the image acquisition device as an accelerated image. In this way, the accelerated image and the first frame of the video to be processed are acquired by the same image acquisition device and have the same image parameters.
[0134] In one implementation, the electronic device can acquire an image captured by the target image acquisition device as an accelerated image. The target image acquisition device is a device that acquires the video to be processed.
[0135] For example, a machine vision system is connected to multiple industrial cameras, namely industrial camera 1, industrial camera 2 and industrial camera 3. The video to be processed is captured by industrial camera 1. Then, the electronic device can obtain any image captured by industrial camera 1 as an accelerated image. In this way, the accelerated image and the first frame of the video to be processed are both captured by industrial camera 1, and therefore have the same image parameters.
[0136] As can be seen, in this embodiment, the electronic device can acquire the image captured by the target image acquisition device as an accelerated image, wherein the target image acquisition device is the acquisition device that acquires the video to be processed. Since the accelerated image is acquired by the acquisition device that acquires the video to be processed, the image parameters of the accelerated image are the same as the image parameters of the first frame of the video to be processed. Therefore, the processing amount required for the format conversion of the accelerated image is not less than the processing amount required for the format conversion of the first frame of the video to be processed. When the processor performs format conversion on the accelerated image, its frequency can be accelerated to a preset frequency. Thus, when performing format conversion on each frame of the video to be processed, the first frame and subsequent frames can be converted at the preset frequency, which can reduce the time consumption of the format conversion of the first frame.
[0137] As one implementation method of this application, such as Figure 4 As shown, prior to the step of acquiring the accelerated image, the method may further include:
[0138] S401, retrieve the processor model;
[0139] S402, Based on the processor model, determine whether the processor supports frequency acceleration;
[0140] S403, if it is determined that the processor supports frequency acceleration, the step of acquiring the accelerated image is performed.
[0141] While most processors support Turbo Boost technology, which automatically increases the frequency when a task starts, some processors do not. Therefore, when an electronic device receives an image format conversion instruction, it can identify the processor model. The processor model serves as an important identifier of processor performance, representing its performance specifications.
[0142] After obtaining the processor's model number, the electronic device can determine whether the processor supports frequency acceleration. If it does not support frequency acceleration, it can directly convert the format of each frame of the video to be processed. If it is determined that the processor supports frequency acceleration, the step of acquiring accelerated images can be performed, thereby accelerating the processor's frequency.
[0143] For example, if the processor model is Core i7-3770K, when an electronic device receives an image format conversion instruction, it can obtain the processor model Core i7-3770K. Based on the Core i7-3770K model, it can be determined that the processor supports Turbo Boost technology, which can automatically accelerate the frequency. Therefore, the electronic device can obtain accelerated images to accelerate the processor frequency.
[0144] As can be seen, in this embodiment, the electronic device can obtain the processor's model number, determine whether the processor supports frequency acceleration based on the processor's model number, and if it is determined that the processor supports frequency acceleration, execute the step of acquiring the accelerated image. Since the accelerated image can be format-converted to accelerate the frequency to a preset frequency when the processor supports frequency acceleration, the first frame and subsequent frames can be format-converted when the processor is at the preset frequency during the format conversion of each frame of the video to be processed. Therefore, the time consumed by the format conversion of the first frame can be reduced.
[0145] As one embodiment of this application, the above format is converted to a color format conversion;
[0146] Prior to the step of acquiring the accelerated image described above, the method may further include:
[0147] Obtain the source and target color formats of the video to be processed;
[0148] If the source color format is different from the target color format, an image format conversion instruction is obtained.
[0149] Since the source and target color formats may be the same when converting the color format of an image, the conversion of the image format does not involve the conversion of the color space, but only the conversion of the encapsulation format, that is, adding the encapsulation format header to the source data. Therefore, there is no need to determine whether the processor supports frequency acceleration, and the image format can be directly converted.
[0150] If the source and target color formats differ during image color format conversion, then color space conversion is required, necessitating further verification of processor support for frequency acceleration. Therefore, electronic devices can obtain the source and target color formats of the video to be processed to determine if they are identical.
[0151] When the source color format and the target color format are different, the electronic device can determine that it has received an image format conversion instruction, and then obtain the processor model to determine whether the processor supports frequency acceleration.
[0152] For example, an electronic device acquires the source color format and target color format of a video to be processed. The source color format of the video to be processed is 16-bit RGB format, and the target color format is 24-bit RGB format. Since the source color format and target color format of the video to be processed are different, it can be determined that the format conversion of the image involves the conversion of different color spaces, and thus it can be determined that the image format conversion instruction has been acquired.
[0153] As can be seen, in this embodiment, the electronic device can obtain the source color format and target color format of the video to be processed. If the source color format and target color format are different, an image format conversion instruction is determined. Upon obtaining the format conversion instruction, an accelerated image can be acquired. When the processor performs format conversion on the accelerated image, it can accelerate the frequency to a preset frequency. Therefore, when converting the format of each frame of the video to be processed, the first frame and subsequent frames can all be converted at the preset frequency, thus reducing the time spent on format conversion of the first frame.
[0154] Figure 5 This is a specific flowchart illustrating image format conversion provided in an embodiment of this application. The following is in conjunction with... Figure 5 The image format conversion method provided in the embodiments of this application will be described with examples. For instance... Figure 5 As shown, an image format conversion method provided in this application embodiment may include the following steps:
[0155] S501, set source and target data parameters;
[0156] Before receiving image format conversion instructions, users can set parameters for the source and target data in electronic devices. For example, industrial cameras and acquisition cards both have an SDK, which is a set of encapsulated API interfaces. Through the API interface, the parameters of the industrial camera can be configured, and the media data of the industrial camera can be obtained through the corresponding protocol process. When users perform color space conversion on the acquired image, the SDK interface can provide corresponding interfaces to configure the source and target color formats.
[0157] S502, Are the source format and the target format the same? If yes, proceed to step S512; if no, proceed to step S503.
[0158] After acquiring the source and target color formats of the video to be processed, the electronic device can determine whether the source and target color formats are the same. If they are the same, it can directly perform container format conversion on each frame of the video. For example, if the source data is MONO8 and is containerized as BMP, the actual conversion process does not involve color space conversion; only a BMP header needs to be added. If the source and target color formats are different, the electronic device can determine that color space conversion is required for the video to be processed.
[0159] S503, color space conversion;
[0160] When the source color format and target color format of the video to be processed are different, the electronic device can determine that the video to be processed needs to be converted in color space.
[0161] S504, retrieve CPU model;
[0162] Electronic devices can obtain the processor model number.
[0163] S505, does it support Turbo Boost? If yes, proceed to steps S506 and S509; if no, proceed to step S513.
[0164] Once the electronic device obtains the processor model, it can determine whether the processor supports Turbo Boost technology.
[0165] S506, enable a separate acceleration thread;
[0166] If the processor supports Turbo Boost, a separate acceleration thread (the first thread) can be enabled to increase the processor frequency.
[0167] S507 generates a pseudo image based on the configuration parameters;
[0168] Electronic devices can generate a pseudo-image (accelerated image) based on the image parameters of the first frame of the video to be processed.
[0169] S508, pseudo-image conversion interface;
[0170] Electronic devices can trigger an acceleration thread to perform format conversion on pseudo-images through the conversion interface provided by the SDK.
[0171] S509, enable clock thread;
[0172] If the processor supports Turbo Boost, the electronic device can start a clock thread at the same time as the acceleration thread to periodically check whether the processor frequency has reached the preset frequency range.
[0173] S510: Periodically check whether the CPU frequency has reached the preset frequency range. If yes, proceed to step S511. If no, continue to check the CPU frequency.
[0174] S511, the hibernation acceleration thread releases resources and notifies the user that acceleration is ready;
[0175] When the CPU frequency is detected to have reached the preset frequency range, the electronic device can put the acceleration thread to sleep to release resources and notify the user that the frequency acceleration is complete. It can then perform format conversion on each frame of the video to be processed.
[0176] S512 does not require color space conversion or acceleration;
[0177] When the source color format and target color format of the video to be processed are the same, there is no need to perform color space conversion, and the electronic device can directly convert the format of each frame of the video to be processed.
[0178] S513, Input data;
[0179] When the source color format and target color format of the video to be processed are the same, or when the source color format and target color format of the video to be processed are different and the processor does not support Turbo Boost, the electronic device can directly acquire the video to be processed.
[0180] When the source color format and target color format of the video to be processed are different and the processor supports Turbo Boost, the electronic device can acquire the video to be processed when the processor frequency reaches the preset frequency range.
[0181] S514, data conversion;
[0182] Electronic devices can perform data conversion (format conversion) on each frame of the video to be processed.
[0183] S515, Is the conversion complete? If yes, end; if no, continue to step S513.
[0184] As can be seen, in the solution provided in this application embodiment, the electronic device can acquire an accelerated image upon receiving an image format conversion instruction, triggering the processor to perform format conversion on the accelerated image. The processing power required for format conversion of the accelerated image is not less than the processing power required for format conversion of the first frame of the video to be processed. The processor frequency is detected, and when the processor frequency is accelerated to a preset frequency, the video to be processed is acquired, and format conversion is performed on each frame of the video to be processed. Since the processor can be triggered to perform format conversion on the accelerated image upon receiving an image format conversion instruction, causing the processor frequency to accelerate to a preset frequency, the first frame and subsequent frames of the video to be processed can be converted at the preset frequency, thus reducing the time consumed by format conversion of the first frame.
[0185] Corresponding to the image format conversion method described above, this application also provides an image format conversion apparatus. The image format conversion apparatus provided in this application embodiment is described below.
[0186] like Figure 6 As shown, an image format conversion device includes:
[0187] The accelerated image acquisition module 610 is used to acquire an accelerated image when an image format conversion instruction is received;
[0188] The first conversion module 620 is used to trigger the processor to perform format conversion on the accelerated image, wherein the amount of processing required for the format conversion of the accelerated image is not less than the amount of processing required for the format conversion of the first frame image of the video to be processed.
[0189] The second conversion module 630 is used to detect the frequency of the processor, and when the frequency of the processor is accelerated to a preset frequency, to acquire the video to be processed and to convert the format of each frame of the video to be processed.
[0190] As can be seen, in the solution provided in this application embodiment, the electronic device can acquire an accelerated image upon receiving an image format conversion instruction, triggering the processor to perform format conversion on the accelerated image. The processing power required for format conversion of the accelerated image is not less than the processing power required for format conversion of the first frame of the video to be processed. The processor frequency is detected, and when the processor frequency is accelerated to a preset frequency, the video to be processed is acquired, and format conversion is performed on each frame of the video to be processed. Since the processor can be triggered to perform format conversion on the accelerated image upon receiving an image format conversion instruction, causing the processor frequency to accelerate to a preset frequency, the first frame and subsequent frames of the video to be processed can be converted at the preset frequency, thus reducing the time consumed by format conversion of the first frame.
[0191] As one embodiment of this application, the accelerated image acquisition module 610 described above may include:
[0192] The accelerated image acquisition submodule is used to start the first thread and acquire accelerated images through the first thread.
[0193] The first conversion module 620 mentioned above may include:
[0194] The first conversion submodule is used to trigger the processor to perform format conversion on the accelerated image through the first thread.
[0195] As one embodiment of this application, the second conversion module 630 described above may include:
[0196] The preset frequency detection submodule is used to start a second thread and detect whether the processor frequency has reached the preset frequency.
[0197] The video to be processed acquisition submodule is used to acquire the video to be processed when the second thread detects that the frequency of the processor has reached the preset frequency.
[0198] As one embodiment of this application, the above-described apparatus may further include:
[0199] The image parameter acquisition module is used to acquire the image parameters of the first frame of the video to be processed before the step of acquiring the accelerated image;
[0200] The aforementioned accelerated image acquisition module 610 may include:
[0201] The first acquisition submodule is used to determine an accelerated image from pre-stored candidate images based on the image parameters of the first frame image; or,
[0202] The accelerated image is generated by determining the width and height of the accelerated image based on the width and height of the first frame image, respectively, and by randomly writing the pixel values of each pixel in the accelerated image, wherein the width of the accelerated image is not less than the width of the first frame image, and the height of the accelerated image is not less than the height of the first frame image.
[0203] As one embodiment of this application, the accelerated image acquisition module 610 described above may include:
[0204] The second acquisition submodule is used to acquire the image acquired by the target image acquisition device as an accelerated image, wherein the target image acquisition device is the acquisition device that acquires the video to be processed.
[0205] As one embodiment of this application, the above-described apparatus may further include:
[0206] The model acquisition module is used to acquire the processor model before the step of acquiring the accelerated image;
[0207] A frequency acceleration determination module is used to determine whether the processor supports frequency acceleration based on the processor's model.
[0208] An accelerated image acquisition module is used to perform the step of acquiring an accelerated image when it is determined that the processor supports frequency acceleration.
[0209] The format is converted to a color format conversion;
[0210] As one embodiment of this application, the above-described apparatus may further include:
[0211] The format acquisition module is used to acquire the source color format and target color format of the video to be processed before the step of acquiring the accelerated image;
[0212] The conversion instruction acquisition module is used to determine and acquire an image format conversion instruction when the source color format is different from the target color format.
[0213] This application also provides an electronic device, such as... Figure 7 As shown, it includes:
[0214] Memory 701 is used to store computer programs;
[0215] When the processor 702 executes the program stored in the memory 701, it implements an image format conversion method as described in any of the above embodiments.
[0216] Furthermore, the aforementioned electronic device may also include a communication bus and / or a communication interface, with the processor 702, the communication interface, and the memory 701 communicating with each other via the communication bus.
[0217] As can be seen, in the solution provided in this application embodiment, the electronic device can acquire an accelerated image upon receiving an image format conversion instruction, triggering the processor to perform format conversion on the accelerated image. The processing power required for format conversion of the accelerated image is not less than the processing power required for format conversion of the first frame of the video to be processed. The processor frequency is detected, and when the processor frequency is accelerated to a preset frequency, the video to be processed is acquired, and format conversion is performed on each frame of the video to be processed. Since the processor can be triggered to perform format conversion on the accelerated image upon receiving an image format conversion instruction, causing the processor frequency to accelerate to a preset frequency, the first frame and subsequent frames of the video to be processed can be converted at the preset frequency, thus reducing the time consumed by format conversion of the first frame.
[0218] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0219] The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0220] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0221] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0222] In another embodiment provided in this application, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the steps of any of the above-described image format conversion methods.
[0223] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to perform any of the image format conversion methods described above.
[0224] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a solid-state drive (SSD), etc.
[0225] 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.
[0226] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments of apparatus, electronic devices, computer-readable storage media, and computer program products are basically similar to the method embodiments, and therefore the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0227] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.
Claims
1. An image format conversion method characterized by, The method includes: Obtain accelerated images; The processor is triggered to perform format conversion on the accelerated image to accelerate the frequency of the processor, wherein the amount of processing required for the format conversion of the accelerated image is not less than the amount of processing required for the format conversion of the first frame of the video to be processed. The frequency of the processor is detected, and when the frequency of the processor is accelerated to a preset frequency, the format of each frame of the video to be processed is converted.
2. The method of claim 1, wherein, The step of acquiring the accelerated image and triggering the processor to perform format conversion on the accelerated image includes: Start the first thread and obtain the accelerated image through the first thread; The first thread triggers the processor to perform format conversion on the accelerated image.
3. The method of claim 1, wherein, The step of detecting the frequency of the processor and, when the processor frequency is accelerated to a preset frequency, converting the format of each frame of the video to be processed includes: Start a second thread, and use the second thread to detect whether the processor frequency has reached the preset frequency; When the second thread detects that the processor frequency has reached the preset frequency, it acquires the video to be processed and performs format conversion on each frame of the video to be processed.
4. The method of claim 1, wherein, Prior to the step of acquiring the accelerated image, the method further includes: Obtain the image parameters of the first frame of the video to be processed; The step of acquiring the accelerated image includes: Based on the image parameters of the first frame image, an accelerated image is determined from pre-stored candidate images; or, Based on the width and height of the first frame image, the width and height of the accelerated image are determined respectively; the pixel values of each pixel point of the accelerated image are randomly written to generate the accelerated image, wherein the width of the accelerated image is not less than the width of the first frame image, and the height of the accelerated image is not less than the height of the first frame image.
5. The method of claim 1, wherein, The step of acquiring the accelerated image includes: The image acquired by the target image acquisition device is obtained as an accelerated image, wherein the target image acquisition device is the acquisition device that acquires the video to be processed.
6. The method according to any one of claims 1 to 5, characterized in that, Prior to the step of acquiring the accelerated image, the method further includes: Get the processor model; Based on the processor model, determine whether the processor supports frequency acceleration; If it is determined that the processor supports frequency acceleration, the step of acquiring the accelerated image is performed.
7. The method according to any one of claims 1 to 5, characterized in that, The format is converted to a color format conversion; Prior to the step of acquiring the accelerated image, the method further includes: Obtain the source and target color formats of the video to be processed; If the source color format is different from the target color format, an image format conversion instruction is obtained.
8. An image format conversion apparatus characterized by comprising: The device includes: Accelerated image acquisition module, used to acquire accelerated images; The first conversion module is used to trigger the processor to perform format conversion on the accelerated image so as to accelerate the frequency of the processor, wherein the amount of processing required for the format conversion of the accelerated image is not less than the amount of processing required for the format conversion of the first frame image of the video to be processed. The second conversion module is used to detect the frequency of the processor and, when the frequency of the processor is accelerated to a preset frequency, to perform format conversion on each frame of the video to be processed.
9. The apparatus according to claim 8, characterized in that, The accelerated image acquisition module includes: The accelerated image acquisition submodule is used to start the first thread and acquire accelerated images through the first thread. The first conversion module includes: The first conversion submodule is used to trigger the processor to perform format conversion on the accelerated image through the first thread; The second conversion module includes: The preset frequency detection submodule is used to start a second thread and detect whether the processor frequency has reached the preset frequency. The video to be processed acquisition submodule is used to acquire the video to be processed and perform format conversion on each frame of the video to be processed when the second thread detects that the frequency of the processor has reached the preset frequency. The device further includes: The image parameter acquisition module is used to acquire the image parameters of the first frame of the video to be processed before the step of acquiring the accelerated image; The accelerated image acquisition module includes: The first acquisition submodule is used to determine an accelerated image from pre-stored candidate images based on the image parameters of the first frame image; or, Used to determine the width and height of the accelerated image based on the width and height of the first frame image respectively; randomly write the pixel values of each pixel in the accelerated image to generate the accelerated image, wherein the width of the accelerated image is not less than the width of the first frame image, and the height of the accelerated image is not less than the height of the first frame image; The accelerated image acquisition module includes: The second acquisition submodule is used to acquire the image acquired by the target image acquisition device as an accelerated image, wherein the target image acquisition device is the acquisition device that acquires the video to be processed; The device further includes: The model acquisition module is used to acquire the processor model before the step of acquiring the accelerated image; A frequency acceleration determination module is used to determine whether the processor supports frequency acceleration based on the processor's model. An accelerated image acquisition module is used to perform the step of acquiring an accelerated image when it is determined that the processor supports frequency acceleration; The format is converted to a color format conversion; The device further includes: The format acquisition module is used to acquire the source color format and target color format of the video to be processed before the step of acquiring the accelerated image; The conversion instruction acquisition module is used to determine and acquire an image format conversion instruction when the source color format is different from the target color format.
10. An electronic device, comprising: include: Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the method described in any one of claims 1-7.
11. A computer readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method described in any one of claims 1-7.