Data processing method, device and electronic equipment
By obtaining the second pixel reading frame containing all valid pixel values during the image data copying process, the problems of large CPU resource consumption and low image data copy quality are solved, and more efficient image data copying is achieved.
Patent Information
- Application Number
- CN202111622674.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-28
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2041-12-28
AI Technical Summary
During the copying of image data, the CPU resource consumption of Linux devices is too large, and the invalid pixel values of the non-target box area are copied into the copying target map due to the OpenCL reading method, which reduces the copy quality of the image data.
When determining that the first pixel reading box includes the target box area and the non-target box area, a second pixel reading box includes all valid pixel values in the first pixel reading box and does not include invalid pixel values in the non-target area, thereby avoiding writing the invalid pixel value to the copy destination map.
It effectively avoids writing invalid pixel values in non-target box areas into the copy target map, improves the copy quality of image data, saves CPU resources, and improves the performance of the application.
Smart Images

Figure CN114372964B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing, and in particular to a data processing method, device and electronic equipment. Background Art
[0002] Image data processing is often used in computer image processing and security industries, and image data copying is a common means of image data processing. Generally speaking, Linux devices not only have limited CPU resources, but also have high requirements for the time consumption of applications. However, when image data is copied frequently or when images with large data volumes are copied, a large amount of CPU resources will inevitably be consumed and the time consumption of the application will increase. In this case, the device hardware unit is usually used for acceleration processing, which can not only save a lot of CPU resources, but also improve the overall performance of the application.
[0003] Graphics Processing Unit (GPU) hardware resources that support Open Computing Language (OpenCL) are commonly used acceleration units in Linux devices and are usually used to optimize acceleration operations. However, when using OpenCL to copy row data, each time the pixel value corresponding to a pixel point is read, only a fixed number of pixel values can be read. Therefore, when copying image data of the target frame area in the original image, if the image data corresponding to the boundary area of the target frame is copied, the pixel values of the non-target frame area may be read, in which only the pixel values in the target frame area are valid pixel values, and all the pixel values in the non-target frame area are invalid pixel values.
[0004] For example, in reference Figure 1a There are three rectangular boxes in the figure, among which rectangular box A is the original copy, rectangular box B is the target box, and rectangular box C is the pixel reading box. There are 4 lines of image data in the pixel reading box, among which circles represent valid pixel values and squares represent invalid pixel values. Figure 1a It can be seen that in the 1st, 2nd and 3rd rows of data, each row of data has a pixel value in the non-target frame area, and this pixel value is an invalid pixel value. In the 4th row of data, all the data is in the non-target frame area, so the pixel value of this 4th row is an invalid row of data.
[0005] In the above case, if the image data read in the pixel reading frame is directly written into the copy destination image, invalid pixel values in the non-target frame area of the copy original image will be added to the copy destination image, thereby reducing the image data copy quality. Summary of the invention
[0006] The present application provides a data processing method, device and electronic device. When determining that a first pixel reading frame includes a target frame area and a non-target frame area, image data in a copy original image is obtained through a second pixel reading frame, thereby avoiding writing invalid pixel values in the non-target area of the copy original image into a copy destination image, thereby improving the image data copy quality.
[0007] In a first aspect, the present application provides a data processing method, the method comprising:
[0008] When acquiring a first pixel reading frame, determining whether the first pixel reading frame includes a target frame area and a non-target frame area, wherein the first pixel reading frame represents an image data reading range, and the target frame area is inside the copy original image;
[0009] When it is determined that the first pixel reading frame includes a target frame area and a non-target frame area, a second pixel reading frame is acquired, wherein the second pixel reading frame includes all valid pixel values in the first pixel reading frame and does not include invalid pixel values in the non-target area;
[0010] The pixel values in the copy original image are read according to the second pixel reading frame, and the pixel values are written into the copy destination image.
[0011] Through the above method, when it is determined that the first pixel reading frame contains the target frame area and the non-target frame area, the image data in the copy original image is obtained through the second pixel reading frame, which can avoid writing invalid pixel values in the non-target area of the copy original image into the copy destination image, thereby improving the image data copy quality.
[0012] In a possible design, determining whether the first pixel reading frame includes a target frame area and a non-target frame area includes:
[0013] Determine whether the pixel reading start position corresponding to the first pixel reading frame is within the target frame area, and the pixel reading end position corresponding to the first pixel reading frame is within the non-target frame area;
[0014] If so, it is determined that the first pixel reading frame includes the target frame area and the non-target frame area.
[0015] Through the above method, the pixel reading starting point position and the pixel reading end point position are used to determine whether the current pixel reading frame contains the target frame area and the non-target frame area.
[0016] In a possible design, obtaining the second pixel reading frame includes:
[0017] Determine a first total number of invalid pixel values corresponding to first image data in the first pixel reading frame, wherein the first image data is a row of image data including valid pixel values and invalid pixel values;
[0018] Determine a first row number of invalid row data corresponding to the first pixel reading frame;
[0019] Re-determine a pixel reading start position and a pixel reading end position according to the first total number and the first number of rows;
[0020] A second pixel reading frame is acquired according to the pixel reading start point position and the pixel reading end point position.
[0021] Through the above method, based on the invalid pixel values corresponding to the first pixel reading frame, the second pixel reading frame is re-determined so that the second pixel reading frame contains all valid pixel values corresponding to the first pixel reading frame and does not contain invalid data in the copied original image.
[0022] In one possible design, determining a first total number of invalid pixel values corresponding to the first image data in the first pixel reading frame includes:
[0023] Determine an M value, wherein the M value represents the number of pixel values in each row of image data obtained during each pixel reading process;
[0024] Calculate a second total number of valid pixel values in the first image data according to the M value and a width value corresponding to the target frame, wherein the width value represents the number of pixel values contained in a line of image data;
[0025] The difference between the M value and the second total is calculated, and the difference is used as the first total.
[0026] By the above method, the total number of invalid pixel values in each line of image data in the first pixel reading frame is calculated, and the total number is used to determine the second pixel reading frame.
[0027] In a possible design, determining the first row number of invalid row data corresponding to the first pixel reading frame includes:
[0028] Determine a K value, wherein the K value represents a row value of image data acquired during each pixel reading process;
[0029] The first number of rows is calculated according to the pixel reading starting point position, the K value and the height value corresponding to the target frame, wherein the height value represents the number of pixel value rows in the image data.
[0030] By means of the above method, the number of rows corresponding to the invalid row data in the first pixel reading frame is calculated, and the number of rows is used to determine the second pixel reading frame.
[0031] In a second aspect, the present application provides a data processing device, the device comprising:
[0032] A judgment module, configured to judge whether the first pixel reading frame contains a target frame area and a non-target frame area when acquiring the first pixel reading frame, wherein the first pixel reading frame represents an image data reading range, and the target frame area is inside the copy original image;
[0033] an acquisition module, configured to acquire a second pixel reading frame when it is determined that the first pixel reading frame includes a target frame area and a non-target frame area, wherein the second pixel reading frame includes all valid pixel values in the first pixel reading frame and does not include invalid pixel values in the non-target area;
[0034] A writing module is used to read the pixel values in the copy original image according to the second pixel reading frame, and write the pixel values into the copy destination image.
[0035] In a possible design, the judgment module is specifically used to:
[0036] Determine whether the pixel reading start position corresponding to the first pixel reading frame is within the target frame area, and the pixel reading end position corresponding to the first pixel reading frame is within the non-target frame area;
[0037] If so, it is determined that the first pixel reading frame includes the target frame area and the non-target frame area.
[0038] In a possible design, the acquisition module is specifically used for:
[0039] Determine a first total number of invalid pixel values corresponding to first image data in the first pixel reading frame, wherein the first image data is a row of image data including valid pixel values and invalid pixel values;
[0040] Determine a first row number of invalid row data corresponding to the first pixel reading frame;
[0041] Re-determine a pixel reading start position and a pixel reading end position according to the first total number and the first number of rows;
[0042] A second pixel reading frame is acquired according to the pixel reading start point position and the pixel reading end point position.
[0043] In a possible design, the acquisition module is further used for:
[0044] Determine an M value, wherein the M value represents the number of pixel values in each row of image data obtained during each pixel reading process;
[0045] Calculate a second total number of valid pixel values in the first image data according to the M value and a width value corresponding to the target frame, wherein the width value represents the number of pixel values contained in a line of image data;
[0046] The difference between the M value and the second total is calculated, and the difference is used as the first total.
[0047] In a possible design, the acquisition module is further used for:
[0048] Determine a K value, wherein the K value represents a row value of image data acquired during each pixel reading process;
[0049] The first number of rows is calculated according to the pixel reading starting point position, the K value and the height value corresponding to the target frame, wherein the height value represents the number of pixel value rows in the image data.
[0050] In a third aspect, the present application provides an electronic device, including:
[0051] Memory, used to store computer programs;
[0052] The processor is used to implement the above-mentioned data processing method steps when executing the computer program stored in the memory.
[0053] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned data processing method steps are implemented.
[0054] Through the above-mentioned data processing method, when it is determined that the first pixel reading frame includes the target frame area and the non-target frame area, the image data in the copied original image is obtained through the second pixel reading frame, wherein the second pixel reading frame includes all valid pixel values in the first pixel reading frame, and at least two boundary lines of the second pixel reading frame coincide with the boundary lines of the target frame area, thereby avoiding writing invalid pixel values in the non-target area of the copied original image into the copied destination image, thereby improving the image data copy quality.
[0055] The technical effects that can be achieved in each of the above-mentioned second to fourth aspects and each of the above-mentioned aspects refer to the technical effects that can be achieved in the above-mentioned first aspect or various possible schemes in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] Figure 1a A schematic diagram of an application scenario of the first pixel reading frame provided in this application;
[0057] Figure 1bA schematic diagram of an application scenario of the second pixel reading frame provided in this application;
[0058] Figure 2 A flowchart of a data processing method provided for this application;
[0059] Figure 3 A schematic diagram of the structure of a data processing device provided in this application;
[0060] Figure 4 A schematic diagram of the structure of an electronic device provided in this application. DETAILED DESCRIPTION
[0061] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The specific operating methods in the method embodiments can also be applied to device embodiments or system embodiments. It should be noted that in the description of the present application, "multiple" is understood as "at least two". "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. A is connected to B, which can represent: A is directly connected to B and A is connected to B through C. In addition, in the description of the present application, words such as "first" and "second" are only used to distinguish the purpose of description, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying order.
[0062] The embodiments of the present application are described in detail below in conjunction with the accompanying drawings.
[0063] When using OpenCL to copy row data, each time the pixel value corresponding to a pixel point is read, only a fixed number of pixel values can be read. Therefore, when copying the image data of the target frame in the original image, if the image data corresponding to the boundary area of the target frame is copied, there may be a situation where the pixel values of the non-target frame area are read, among which only the pixel values within the target frame area are valid pixel values, and the pixel values in the non-target frame area are all invalid pixel values.
[0064] For example, in reference Figure 1a There are three rectangular boxes in the figure, among which rectangular box A is the original copy, rectangular box B is the target box, and rectangular box C is the pixel reading box. There are 4 lines of image data in the pixel reading box, among which circles represent valid pixel values and squares represent invalid pixel values. Figure 1a It can be seen that in the 1st, 2nd and 3rd rows of data, each row of data has a pixel value in the non-target frame area, and this pixel value is an invalid pixel value. In the 4th row of data, all the data is in the non-target frame area, so the pixel value of this 4th row is an invalid row of data.
[0065] In the above case, if the image data read in the pixel reading frame is directly written into the copy destination image, invalid pixel values in the non-target frame area of the copy original image will be added to the copy destination image, thereby reducing the image data copy quality.
[0066] In order to solve the above problems, the present application provides a data processing method, when it is determined that the first pixel reading frame contains a target frame area and a non-target frame area, a second pixel reading frame is obtained, wherein the second pixel reading frame contains all valid pixel values in the first pixel reading frame and does not contain invalid pixel values in the non-target area, and finally the image data of the copy original image is obtained through the second pixel reading frame, and the image data is written into the copy destination image.
[0067] By using the above method, invalid pixel values in the non-target frame area of the original image can be avoided from being written into the target image, thereby improving the quality of the image data copy. The method and device described in the embodiment of the present application are based on the same technical concept. Since the principles of the problems solved by the method and the device are similar, the embodiments of the device and the method can refer to each other, and the repeated parts will not be repeated.
[0068] like Figure 2 As shown, it is a flowchart of a data processing method provided by the present application, which specifically includes the following steps:
[0069] S21, when acquiring the first pixel reading frame, determining whether the first pixel reading frame includes a target frame area and a non-target frame area;
[0070] S22, when it is determined that the first pixel reading frame includes the target frame area and the non-target frame area, obtaining a second pixel reading frame, wherein the second pixel reading frame includes all valid pixel values in the first pixel reading frame and does not include invalid pixel values in the non-target area;
[0071] S23, reading the pixel values in the copy original image according to the second pixel reading frame, and writing the pixel values into the copy destination image.
[0072] In the embodiment of the present application, when copying the image data corresponding to the target frame boundary area in the copied original image, it is necessary to first obtain the first pixel reading frame, wherein the first pixel reading frame represents the image data reading range.
[0073] After obtaining the first pixel reading frame, further, it is determined whether the first pixel reading frame contains a target frame area and a non-target frame area, wherein the target frame area is inside the copy original image, and the specific determination method is:
[0074] Determine whether the pixel reading starting point position corresponding to the first pixel reading frame is within the target frame area, and the pixel reading ending point position corresponding to the first pixel reading frame is within the non-target frame area; if so, determine that the first pixel reading frame includes the target frame area and the non-target frame area.
[0075] Through the above method, it can be determined that the first pixel reading frame includes a target frame area and a non-target frame area, wherein the pixel values in the target frame area are valid pixel values, while the pixel values in the non-target area are invalid pixel values. Therefore, if the image data in the copy original image is obtained according to the first pixel reading frame and the image data is written into the copy destination image, invalid pixel values corresponding to the non-target frame area in the copy original image will be added to the copy destination image.
[0076] In order to solve the above problem, it is necessary to obtain a second pixel reading frame, wherein the second pixel reading frame contains all valid pixel values in the first pixel reading frame and does not contain invalid pixel values in the non-target area. In the embodiment of the present application, the specific method for obtaining the second pixel reading frame can be:
[0077] First, a first total number of invalid pixel values corresponding to first image data in a first pixel reading frame is determined, wherein the first image data is a row of image data including valid pixel values and invalid pixel values.
[0078] In an embodiment of the present application, the method for determining the first total number may be: determining an M value, wherein the M value represents the number of pixel values in each row of image data obtained during each pixel reading process, which may be 4, 8, or 16, and the data type may be vxc_uchar4, vxc_uchar8, vxc_uchar16, float4, or other data types. Then, according to the M value and the width value corresponding to the target frame, the second total number of valid pixel values in the first image data is calculated, wherein the width value represents the number of pixel values contained in a row of image data, and further, the difference between the M value and the second total number is calculated, and the difference is used as the first total number.
[0079] At the same time, the first row number of the invalid row data corresponding to the first pixel reading frame is determined.
[0080] In an embodiment of the present application, the method for determining the first number of rows may be: determining a K value, wherein the K value represents the image data row value obtained during each pixel reading process, and then calculating the first number of rows according to the pixel reading starting point position, the K value, and the height value corresponding to the target frame, wherein the height value represents the number of pixel value rows in the image data. The specific calculation method is: using the sum of the ordinate corresponding to the pixel reading starting point position and the K value, minus the height value corresponding to the target frame, to obtain the first number of rows.
[0081] Further, based on the first total number and the first row number, the pixel reading starting point position and the pixel reading end point position are re-determined. The specific determination method is: the pixel reading starting point position and the pixel reading end point corresponding to the first pixel reading frame are simultaneously moved in the opposite direction of the pixel reading by the first row number and the number of columns corresponding to the first total number to obtain a new pixel reading starting point position and the pixel reading end point position.
[0082] Next, the second pixel reading frame is obtained according to the pixel reading starting position and the pixel reading end position. Figure 1a , after moving the rectangular frame C up one row and left one column, the second pixel reading frame obtained is as follows Figure 1b As shown in the rectangular box D in , the rectangular box D contains all the valid values in the rectangular box C and does not contain invalid pixel values in the non-target box area.
[0083] Further, by obtaining the image data in the original copy image through the second pixel reading frame and writing the image data into the target copy image, invalid pixel values corresponding to the newly added non-target frame area in the target copy image can be avoided, thereby improving the image data copy quality.
[0084] In a possible application scenario, when the first pixel reading frame is obtained, the pixel reading starting point position and the pixel reading ending point position corresponding to the first pixel reading frame are both within the target frame area, indicating that the first pixel reading frame only contains the target frame area. Therefore, all the image data obtained through the first pixel reading frame are valid pixel values, and the image data copying can be completed by directly writing the image data into the copy destination image.
[0085] In another possible application scenario, when the first pixel reading frame is obtained, the pixel reading starting point position and the pixel reading ending point position corresponding to the first pixel reading frame are both within the non-target frame area, indicating that the first pixel reading frame only contains the non-target frame area. Therefore, all the image data obtained through the first pixel reading frame contain invalid pixel values. At this time, the image data is directly revoked and not written into the copy destination image.
[0086] Furthermore, in order to elaborate on the data processing method provided by the present application in more detail, the above data processing method is further described below using an application scenario based on OpenCL.
[0087] In this application scenario, image data copying is based on CPU+GPU collaborative processing, which utilizes the powerful data computing capability of GPU, the logical scheduling processing capability of CPU, and the OpenCL parallelization language to fully utilize the platform hardware resources to accelerate data copying operations.
[0088] First, according to the target frame area SrcRect of the original image Srcimg, the pixel reading starting point coordinates, width value and height information corresponding to the target frame area SrcRect in the original image Srcimg are obtained. Similarly, according to the target frame area DstRect of the target image Dstimg, the pixel writing starting point coordinates, width value and height information corresponding to the target frame area DstRect in the target image Dstimg are obtained.
[0089] In this application scenario, the coordinates of the upper left corner vertex of the copied original image are set as the origin, the right is the positive direction of the x-axis, and the downward is the positive direction of the y-axis. Then SrcRect consists of four data, namely the coordinates of the upper left corner of the target box in the copied original image (Sx0, Sy0) and the coordinates of the lower right corner (Sx1, Sy1). DstRect is also composed of four data, namely the coordinates of the upper left corner of the target box in the copied destination image (Dx0, Dy0) and the coordinates of the lower right corner (Dx1, Dy1). According to the above coordinate information, the width value SRw and height value SRh corresponding to the target box area SrcRect, as well as the width value DRw and height value DRh corresponding to the target box area DstRect are calculated. Since the width values corresponding to SrcRect and DstRect are consistent, and the width values corresponding to SrcRect and DstRect are consistent, the above SRw and DRw are uniformly recorded as Rw, and SRh and DRh are uniformly recorded as Rh.
[0090] Assume that during the OpenCL operation, the starting offset value of the global id (x, y, z) of each work-item is idx, and the coordinates of idx after the offset (Sx0, Sy0) are Srcpos, which is the starting position for reading pixel values from SrcRect of Srcimg, and the coordinates of idx after the offset (Dx0, Dy0) are Dstpos, which is the starting position for writing pixel values from DstRect of Dstimg. Among them, the work item is Figure 2 The pixel reading box shown in .
[0091] Each time, the work item reads the pixel values of a fixed number of rows of pixels from the Srcpos position of Srcimg, and then writes them to the Dstpos position of Dstimg.
[0092] Based on the above content, each work item reads Rows rows of image data each time, and each row of image data contains num pixel values, where num can be 4, 8, 16, Rows can be 1, 2, 3, 4, ..., and the data type can be vxc_uchar4, vxc_uchar8, vxc_uchar16, float4, or other data types.
[0093] Each work item will obtain the starting address idx of the current work item through get_global_id. If idx.x<0 or idx.y<0, it means that the starting address (idx.x, idx.y) is outside the target frame area, which is an invalid pixel reading starting point. You can directly return to end the copy task of the current work item; otherwise, judge whether Srcpos and Dstpos are in the target frame area, where Srcpos and Dstpos are both int2 types, and the calculation formulas are: Srcpos=idx+(int2)(Sx0, Sy0) and Dstpos=idx+(int2)(Dx0, Dy0). Then, different processing strategies are adopted according to different judgment results, including:
[0094] When idx.x+Sx0>Rw+Sx0, that is, idx.x>Rw, it indicates that the x-coordinate position Srcpos.x corresponding to Srcpos is already on the right side of the right frame of SrcRect in Srcimg, which means that Srcpos is in the non-target frame area. In this case, no copy operation is required, and the copy task of the current work item is ended directly.
[0095] When idx.x+Sx0+num≤Rw+Sx0, that is, idx.x+num≤Rw, it means that Srcpos.x is inside SrcRect of Srcimg, and the end point coordinate position Srcpos.x+num-1 after reading num pixels from Srcpos.x is still inside SrcRect. Therefore, all the num pixel values read from Srcpos.x of Srcimg are valid pixel values.
[0096] When Rw + Sx0 < idx.x + Sx0 + num and idx.x + Sx0 < Rw + Sx0, that is, idx.x + Sx0 < Rw + Sx0 < idx.x + Sx0 + num, or equivalently idx.x < Rw < idx.x + num, it means that Srcpos.x is inside the SrcRect of Srcimg, and the end coordinate position Srcpos.x + num - 1 after reading num pixels starting from Srcpos.x is outside the right frame of SrcRect. If num pixel values of a row are read from Srcpos.x at this time, then the first part of these num pixel values is inside SrcRect, and the second part is outside the right frame of SrcRect. Only the pixel values inside SrcRect are valid pixel values, and the pixel values outside SrcRect are all invalid pixel values. If these num pixel values are directly written to the coordinate position of Dstpos in Dstimg at this time, it will cause some invalid pixel values to be written into the Dstimg. If this problem is to be solved, the Srcpos.x corresponding to the current work item needs to be processed as follows:
[0097] Calculate the remainder c through Rw % num. The remainder c represents the number of valid pixel values that need to be copied in each row of image data corresponding to the current work item. Through the value of c, the number of invalid pixels that do not require copying in the same row of image data can be calculated as m = num - c. For example, the width value of the SrcRect to be copied currently is 329 pixels, and 16 pixels are read each time. The first 320 pixels inside the frame are read in the first 20 times, and the last 9 pixels inside the frame and 7 pixels outside the frame are read in the 21st time. The remainder of 329 % 16 is exactly 9. In this way, we know that the first 9 pixel values read this time are valid, and the last 7 pixel values are invalid.
[0098] Next, move Srcpos.x forward by m pixel points. Because if num pixel values are directly read from Srcpos.x, then the first c pixel values among these num pixel values are valid pixel values inside the SrcRect, and the last m data are invalid pixel values outside the SrcRect. At this time, if Srcpos.x is moved forward by m pixel points, then the positions of Srcpos.x and Srcpos.x + num - 1 are all inside the SrcRect of Srcimg. As known above, Srcpos.x = Srcpos.x – m, that is, Srcpos.x = Srcpos.x + c – num.
[0099] Similarly, after the position of Dstpos needs to be moved forward by m pixel points, the abscissa position Dstpos.x corresponding to Dstpos and the pixel writing end position DstPos.x + num - 1 are all inside the DstRect of Dstimg. As can be seen from the above, Dstpos.x = Dstpos.x – m, that is, Dstpos.x = Dstpos.x + c - num.
[0100] The above content determines whether Srcpos is inside the target box area through Srcpos.x, and different handling measures are taken for different situations. Next, it is still necessary to determine whether Srcpos is inside the target box area through the y - coordinate position Srcpos.y corresponding to Srcpos, and different handling measures are taken for different situations. These two judgment methods are carried out simultaneously.
[0101] When idx.y + Sy0 > Rh + Sy0, that is, idx.y > Rh, it means that Srcpos.y is below the lower border of the SrcRect of Srcimg. At this time, no copy operation is required, and the copy task of the current work item is directly ended.
[0102] When idx.y + Sy0 + Rows ≤ Rh + Sy0, that is, idx.y + Rows ≤ Rh, it means that both Srcpos.y and Srcpos.y + Rows - 1 are inside the SrcRect box, that is, the y - coordinate after reading Rows rows of data from Srcpos is also within the range of Rh of the SrcRect box.
[0103] When Rh + Sy0 < idx.y + Sy0 + Rows and idx.y + Sy0 < Rh + Sy0, that is, idx.y + Sy0 < Rh + Sy0 < idx.y + Sy0 + Rows, that is, idx.y < Rh < idx.y + Rows, it indicates that Srcpos.y is inside the SrcRect box, but the end coordinate Srxpos.y + Rows - 1 after reading Rows rows starting from Srcpos.y is below the lower border of the SrcRect, and the row data below the lower border of the SrcRect is invalid row data. At this time, the following processing needs to be performed on Srcpos.y corresponding to the current work item:
[0104] The number of rows outside the SrcRect box is calculated by the formula r=idx.y+Rows-Rh. For example, the height value of the SrcRect box is 19 rows of pixels. Each work item reads 4 rows at a time, so the first 4 work items will read 16 rows. Among the 4 rows of pixel values read by the last work item, 3 rows are within the SrcRect box, which are valid row data, and 1 row is outside the SrcRect box, which is invalid row data. The starting point idx.y of the last work item is 16, and the 4 rows of image data corresponding to idx.y of 16, 17, 18, and 19 will be read (since the coordinates are counted from 0, all idx.y=19 means the 20th row). Using the formula r=idx.y+Rows-Rh=16+4-19=1, it can also be calculated that 1 row of image data is invalid row data.
[0105] Furthermore, the starting Srcpos.y coordinate of the work item is offset upward by r rows, so that the image data of the Rows rows read by the current work item are all inside SrcRect. Similarly, the Dstpos.y coordinate should also be offset according to the same principle.
[0106] It can be seen from the above that Srcpos.y=Srcpos.y–r, that is, Srcpos.y=Srcpos.y+Rh-Rows-idx.y; Dstpos.y=Dstpos.y–r, that is, Dstpos.y=Dstpos.y+Rh-Rows-idx.y.
[0107] Through the above method, read Rows from the position of Srcpos of Srcimg, each row has num pixel values, and write all these pixel values to the position of Dstpos of Dstimg. In this way, all the Rows*num pixel values read and written by each work item are valid pixel values. In addition, this application scenario adopts the form of OpenCL self-programming, the code logic is simple, the versatility is strong, and the number of pixels and rows read by the work item each time can be modified according to the actual application requirements.
[0108] Based on the same inventive concept, the present application also provides a data processing device, such as Figure 3 FIG. 1 is a schematic diagram of a data processing device in the present application, and the device includes:
[0109] A judgment module 31 is used to judge whether the first pixel reading frame contains a target frame area and a non-target frame area when acquiring the first pixel reading frame, wherein the first pixel reading frame represents the image data reading range, and the target frame area is inside the copy original image;
[0110] An acquisition module 32 is used to acquire a second pixel reading frame when it is determined that the first pixel reading frame includes a target frame area and a non-target frame area, wherein the second pixel reading frame includes all valid pixel values in the first pixel reading frame and does not include invalid pixel values in the non-target area;
[0111] The writing module 33 is used to read the pixel values in the copy original image according to the second pixel reading frame, and write the pixel values into the copy destination image.
[0112] In a possible design, the judging module 31 is specifically used for:
[0113] Determine whether the pixel reading start position corresponding to the first pixel reading frame is within the target frame area, and the pixel reading end position corresponding to the first pixel reading frame is within the non-target frame area;
[0114] If so, it is determined that the first pixel reading frame includes the target frame area and the non-target frame area.
[0115] In a possible design, the acquisition module 32 is specifically used for:
[0116] Determine a first total number of invalid pixel values corresponding to first image data in the first pixel reading frame, wherein the first image data is a row of image data including valid pixel values and invalid pixel values;
[0117] Determine a first row number of invalid row data corresponding to the first pixel reading frame;
[0118] Re-determine a pixel reading start position and a pixel reading end position according to the first total number and the first number of rows;
[0119] A second pixel reading frame is acquired according to the pixel reading start point position and the pixel reading end point position.
[0120] In a possible design, the acquisition module 32 is further used for:
[0121] Determine an M value, wherein the M value represents the number of pixel values in each row of image data obtained during each pixel reading process;
[0122] Calculate a second total number of valid pixel values in the first image data according to the M value and a width value corresponding to the target frame, wherein the width value represents the number of pixel values contained in a line of image data;
[0123] The difference between the M value and the second total is calculated, and the difference is used as the first total.
[0124] In a possible design, the acquisition module 32 is further used for:
[0125] Determine a K value, wherein the K value represents a value of an image data row obtained during each pixel reading process;
[0126] The first number of rows is calculated according to the pixel reading starting point position, the K value and the height value corresponding to the target frame, wherein the height value represents the number of pixel value rows in the image data.
[0127] Through the above-mentioned data processing device, when it is determined that the first pixel reading frame includes the target frame area and the non-target frame area, the image data in the copied original image is obtained through the second pixel reading frame, wherein the second pixel reading frame includes all valid pixel values in the first pixel reading frame, and at least two boundary lines of the second pixel reading frame coincide with the boundary lines of the target frame area, thereby avoiding writing invalid pixel values in the non-target area of the copied original image into the copied destination image, thereby improving the image data copy quality.
[0128] Based on the same inventive concept, an electronic device is also provided in an embodiment of the present application, and the electronic device can realize the functions of the aforementioned data processing device, referring to Figure 4 , the electronic device comprises:
[0129] At least one processor 41, and a memory 42 connected to the at least one processor 41. The specific connection medium between the processor 41 and the memory 42 is not limited in the embodiment of the present application. Figure 4 In the example, the processor 41 and the memory 42 are connected via the bus 40. The bus 40 is Figure 4 The connection between other components is shown by bold lines, and is not intended to be limiting. The bus 40 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 Only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. Alternatively, the processor 41 can also be called a controller, and there is no limitation on the name.
[0130] In the embodiment of the present application, the memory 42 stores instructions that can be executed by at least one processor 41. The at least one processor 41 can execute the data processing method discussed above by executing the instructions stored in the memory 42. The processor 41 can implement Figure 3 The functions of each module in the device shown.
[0131] Among them, the processor 41 is the control center of the device, and can use various interfaces and lines to connect the various parts of the entire control device. By running or executing instructions stored in the memory 42 and calling data stored in the memory 42, the various functions of the device and processing data, the device can be monitored as a whole.
[0132] In a possible design, the processor 41 may include one or more processing units, and the processor 41 may integrate an application processor and a modem processor, wherein the application processor mainly processes an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the modem processor may not be integrated into the processor 41. In some embodiments, the processor 41 and the memory 42 may be implemented on the same chip, and in some embodiments, they may also be implemented separately on separate chips.
[0133] The processor 41 may be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, and may implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the data processing method disclosed in the embodiments of the present application may be directly embodied as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
[0134] The memory 42 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 42 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (Random Access Memory, RAM), a static random access memory (Static Random Access Memory, SRAM), a programmable read-only memory (Programmable Read Only Memory, PROM), a read-only memory (Read Only Memory, ROM), an electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic memory, a disk, an optical disk, etc. The memory 42 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 42 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.
[0135] By designing and programming the processor 41, the code corresponding to the data processing method described in the above embodiment can be fixed into the chip, so that the chip can execute the code when running. Figure 2The steps of the data processing method of the embodiment shown are as follows: How to design and program the processor 41 is a technique well known to those skilled in the art and will not be described in detail here.
[0136] Based on the same inventive concept, an embodiment of the present application further provides a storage medium, which stores computer instructions. When the computer instructions are executed on a computer, the computer executes the data processing method discussed above.
[0137] In some possible implementations, various aspects of the data processing method provided by the present application may also be implemented in the form of a program product, which includes program code. When the program product is run on an apparatus, the program code is used to enable the control device to execute the steps of the data processing method according to various exemplary implementations of the present application described above in this specification.
[0138] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0139] The present application is described with reference to the flowchart and / or block diagram of the method, device (system) and computer program product according to the embodiment of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, and the combination of the process and / or box in the flowchart and / or block diagram can be realized by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce a device for realizing the function specified in one process or multiple processes in the flowchart and / or one box or multiple boxes in the block diagram.
[0140] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device that implements the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.
[0141] These computer program instructions may also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, whereby the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.
[0142] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A data processing method, characterized in that: The method comprises: When acquiring a first pixel reading frame, determining whether the first pixel reading frame includes a target frame area and a non-target frame area, wherein the first pixel reading frame represents an image data reading range, and the target frame area is inside the copy original image; When determining that the first pixel reading frame includes a target frame area and a non-target frame area, determining a first total number of invalid pixel values corresponding to first image data in the first pixel reading frame, wherein the first image data is a row of image data including valid pixel values and invalid pixel values; Determine a first row number of invalid row data corresponding to the first pixel reading frame; Re-determine a pixel reading start position and a pixel reading end position according to the first total number and the first row number; According to the pixel reading starting position and the pixel reading ending position, a second pixel reading frame is acquired; wherein the second pixel reading frame includes all valid pixel values in the first pixel reading frame and does not include invalid pixel values in the non-target frame area; The pixel values in the copy original image are read according to the second pixel reading frame, and the pixel values are written into the copy destination image.
2. The method according to claim 1, characterized in that Determining whether the first pixel reading frame includes a target frame area and a non-target frame area includes: Determine whether the pixel reading start position corresponding to the first pixel reading frame is within the target frame area, and the pixel reading end position corresponding to the first pixel reading frame is within the non-target frame area; If so, it is determined that the first pixel reading frame includes the target frame area and the non-target frame area.
3. The method according to claim 1, characterized in that Determining a first total number of invalid pixel values corresponding to the first image data in the first pixel reading frame includes: Determine an M value, wherein the M value represents the number of pixel values in each row of image data obtained during each pixel reading process; Calculate a second total number of valid pixel values in the first image data according to the M value and a width value corresponding to the target frame, wherein the width value represents the number of pixel values contained in a line of image data; The difference between the M value and the second total is calculated, and the difference is used as the first total.
4. The method according to claim 1, characterized in that The determining the first row number of the invalid row data corresponding to the first pixel reading frame includes: Determine a K value, wherein the K value represents a row value of image data acquired during each pixel reading process; The first number of rows is calculated according to the pixel reading starting point position, the K value and the height value corresponding to the target frame, wherein the height value represents the number of pixel value rows in the image data.
5. A data processing device, characterized in that: The device comprises: A judgment module, configured to judge whether the first pixel reading frame contains a target frame area and a non-target frame area when acquiring the first pixel reading frame, wherein the first pixel reading frame represents an image data reading range, and the target frame area is inside the copy original image; An acquisition module, configured to determine a first total number of invalid pixel values corresponding to first image data in the first pixel reading frame when it is determined that the first pixel reading frame includes a target frame area and a non-target frame area, wherein the first image data is a row of image data including valid pixel values and invalid pixel values; Determine a first row number of invalid row data corresponding to the first pixel reading frame; Re-determine a pixel reading start position and a pixel reading end position according to the first total number and the first row number; According to the pixel reading starting position and the pixel reading ending position, a second pixel reading frame is acquired; wherein the second pixel reading frame includes all valid pixel values in the first pixel reading frame and does not include invalid pixel values in the non-target frame area; A writing module is used to read the pixel values in the copy original image according to the second pixel reading frame, and write the pixel values into the copy destination image.
6. The device according to claim 5, characterized in that The judgment module is specifically used for: Determine whether the pixel reading start position corresponding to the first pixel reading frame is within the target frame area, and the pixel reading end position corresponding to the first pixel reading frame is within the non-target frame area; If so, it is determined that the first pixel reading frame includes the target frame area and the non-target frame area.
7. The device according to claim 5, characterized in that The acquisition module is also used for: Determine an M value, wherein the M value represents the number of pixel values in each row of image data obtained during each pixel reading process; Calculate a second total number of valid pixel values in the first image data according to the M value and a width value corresponding to the target frame, wherein the width value represents the number of pixel values contained in a line of image data; The difference between the M value and the second total is calculated, and the difference is used as the first total.
8. The device according to claim 5, characterized in that The acquisition module is also used for: Determine a K value, wherein the K value represents a row value of image data acquired during each pixel reading process; The first number of rows is calculated according to the pixel reading starting point position, the K value and the height value corresponding to the target frame, wherein the height value represents the number of pixel value rows in the image data.
9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to implement the method steps of any one of claims 1 to 4 when executing the computer program stored in the memory.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps of any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Implementation method of GPU copy buffer area based on OpenGL copy command
CN111047501A