Code scanning preview method and electronic equipment

By calculating the offset in the code scanning device and cropping the original image and sampling the first preview image according to the screen preview resolution, the problem of slow scanning preview speed and image distortion in the existing code scanning device is solved, and fast and accurate preview effect of scanning code.

CN119450200APending Publication Date: 2025-02-14FUJIAN LANDI COMMERCIAL EQUIPMENT CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411443911.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-16
Publication Date
2025-02-14

AI Technical Summary

Technical Problem

Existing code scanning devices have problems such as image distortion, slow preview speed and positioning lights affecting the acquisition accuracy in terms of code scanning preview.

Method used

By obtaining the crop resolution in the scanning code requirement and the shooting resolution of the original image captured by the camera, calculate the offset and crop the original image to obtain the first preview image. Then, the sampling interval is calculated based on the screen preview resolution and the crop resolution, and the first preview image is sampled to obtain a second preview image, and displayed on the screen.

Benefits of technology

Achieve fast and accurate preview of the code scan result, reducing the number of pixels to be processed, improving the preview speed, and avoiding image distortion.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119450200A_ABST
    Figure CN119450200A_ABST
Patent Text Reader

Abstract

The invention discloses a code scanning preview method and electronic equipment, and the method comprises the steps: obtaining a code scanning demand which comprises a preset cutting resolution; obtaining the shooting resolution of an original image shot by the camera, and calculating an offset according to the shooting resolution and the cutting resolution; cutting the original image according to the cutting resolution and the offset to obtain a first preview image; obtaining a screen preview resolution, wherein the screen preview resolution is smaller than the cutting resolution; calculating a sampling interval according to the cutting resolution and the screen preview resolution; and sampling the first preview image according to the sampling interval to obtain a second preview image, and displaying the second preview image on the screen. According to the method, important parts in the original image can be intercepted and previewed through the cutting resolution and the offset, information in the whole original image does not need to be displayed, and the data processing speed is guaranteed; and the sampling interval is calculated, and the first preview image is sampled according to the sampling interval to obtain the second preview image, so that the preview speed is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of scanning, and in particular to a code scanning preview method and an electronic device. Background Art

[0002] In the related art, simple code scanning devices are not equipped with the code scanning image preview function. Even if they have the corresponding function, there are still problems of image distortion and slow preview speed. Another type of code scanning device achieves a preview of the scanning position by adding a red positioning light to the hardware. The positioning light will affect the accuracy of the image acquisition results. Summary of the invention

[0003] The technical problem to be solved by the present invention is to provide a code scanning preview method and an electronic device to achieve fast and accurate code scanning result preview.

[0004] In order to solve the above technical problems, a technical solution adopted by the present invention is:

[0005] A code scanning preview method is applied to a code scanning device, the code scanning device includes a screen, and the method includes:

[0006] Obtaining a code scanning requirement, wherein the code scanning requirement includes a preset cropping resolution;

[0007] Obtaining a shooting resolution of the original image shot by the camera, and calculating an offset according to the shooting resolution and the cropping resolution;

[0008] Cropping the original image according to the cropping resolution and the offset to obtain a first preview image;

[0009] Acquire a screen preview resolution, where the screen preview resolution is smaller than the cropping resolution;

[0010] Calculate a sampling interval according to the cropping resolution and the screen preview resolution;

[0011] The first preview image is sampled according to the sampling interval to obtain a second preview image, and the second preview image is displayed on the screen.

[0012] In order to solve the above technical problems, another technical solution adopted by the present invention is:

[0013] An electronic device includes a memory, a processor, and a computer program stored in the memory and running on the processor. When the processor executes the computer program, each step in the above-mentioned code scanning preview method is implemented.

[0014] The beneficial effects of the present invention are: determining the cropping resolution according to the code scanning requirements, calculating the offset according to the cropping resolution and the shooting resolution of the original image captured by the camera, and cropping the original image according to the cropping resolution and the offset to obtain the first preview image; the present application crops the original image by the cropping resolution and the offset to obtain the first preview image, and can intercept and preview the important part of the original image without displaying the information in the entire original image, thereby ensuring the speed of data processing. After the original image is cropped according to the cropping resolution and the offset to obtain the first preview image, the screen preview resolution is obtained. If the screen preview resolution is less than the cropping resolution, the sampling interval is calculated according to the cropping resolution and the screen preview resolution, and the first preview image is sampled according to the sampling interval to obtain the second preview image, further reducing the number of pixels to be processed, thereby ensuring the preview speed, and the preview position can be adjusted according to actual needs; moreover, the first preview image is sampled according to the sampling interval to obtain the second preview image, and image distortion can be avoided while improving the preview speed, thereby ensuring the accuracy of the acquisition result. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] Figure 1 A flowchart of a code scanning preview method provided by an embodiment of the present invention;

[0016] Figure 2 A detailed implementation flowchart of a code scanning preview method provided by an embodiment of the present invention;

[0017] Figure 3 A sampling flow chart of a code scanning preview method provided by an embodiment of the present invention;

[0018] Figure 4 A schematic diagram of the camera image output direction and screen direction provided in an embodiment of the present invention;

[0019] Figure 5 A schematic diagram of the mechanical structure of an electronic device provided by an embodiment of the present invention

[0020] Figure 6 A schematic diagram of the framework structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0021] In order to make the technical problems, technical solutions and beneficial effects to be solved by the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0022] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.

[0023] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.

[0024] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0025] In the related art, simple code scanning devices are not equipped with the code scanning image preview function. Even if they have the corresponding function, there are still problems of image distortion and slow preview speed. Another type of code scanning device achieves a preview of the scanning position by adding a red positioning light to the hardware. The positioning light will affect the accuracy of the image acquisition results.

[0026] Specifically, the barcode scanning gun usually does not provide a corresponding preview of the scanning result. Instead, it locates the scanning position by adding hardware such as a red aiming light and a fill white light, which increases the hardware complexity and requires the control process of adding an aiming light and a white light. In addition, the light exposure will affect the automatic exposure of the camera during the image acquisition process, resulting in abnormal brightness in some areas of the acquired image. If the abnormal area is located in the barcode area, it may affect the accuracy of the recognition result or cause recognition failure. Some devices that provide previews usually only directly preview and display the acquired images, so that the amount of data processed is large and the preview speed is slow. As for the optimization of image processing, only a simple zooming in and out will cause image distortion and fail to achieve the preview effect. In addition, the zooming process also requires calculation, and the slow preview speed further affects the scanning speed, and the user's subjective experience is not good.

[0027] In addition, the image capture format and image display format are usually inconsistent. The captured image needs to be converted before it can be displayed on the screen. The pixel-by-pixel format conversion of the captured image will also slow down the preview speed, further affecting the user experience. Common original output image formats captured by cameras include YUV420, YUV422, RGB565, etc., but in the decoding scenario, the decoding library only needs the image Y brightness information and UV color information, so basically when configuring the camera, the image output format of YUV42 will be set so that the captured image can be used directly in the decoding process. However, the general terminal device screen cannot directly display YUV image data, and it needs to be converted through a conversion formula; from the conversion formula, it can be seen that the constant may be a floating point number, and the conversion process may involve floating point number multiplication operations. According to computer principles, floating point multiplication operations are very time-consuming, and the resolution of the original image captured is usually 640*480. Such a conversion operation for each pixel in an image with a common resolution of 640*480 will greatly affect the smoothness of the preview and the scanning speed.

[0028] In terms of methods to reduce the amount of data to be processed during the display process, the simple POS platform often uses the interval sampling method of the original image obtained by shooting to scale the image by integer multiples, which greatly limits the diversity of application development; or uses a third party such as the OPEN CV library for non-integer scaling, but the introduction of the third library will inevitably bring more dependencies, which will eventually increase the complexity of the compilation environment and the size of the executable file. In addition, the simple POS platform is often resource-limited and cannot support such a large algorithm library. It is not possible to introduce another huge algorithm library because of a small demand.

[0029] In order to solve the above problems, the present application provides a code scanning preview method and an electronic device. The following specifically introduces a code scanning preview method of the present application.

[0030] The code scanning preview method in this application can be used on various code scanning devices with display screens, including but not limited to barcode scanning devices, QR code scanning devices, and POS machines.

[0031] Please refer to Figure 1-4 The following specifically describes the steps of the code scanning preview method in the present invention.

[0032] S110, obtaining a code scanning requirement, where the code scanning requirement includes a preset cropping resolution;

[0033] S120, obtaining a shooting resolution of the original image shot by the camera, and calculating an offset according to the shooting resolution and the cropping resolution;

[0034] In an optional implementation, the shooting resolution is the resolution of the original image when the camera shoots it. For example, in order to ensure the speed of the decoding library, the resolution usually used by the camera is 640*480, which corresponds to Figure 4 The resolution of the Image area in the image. To ensure the best decoding depth of field and decoding speed, the original image shooting resolution is also 640*480. The screen resolution is usually lower than the camera resolution. For example, the screen resolution of a simple payment terminal POS is generally 320*240, which corresponds to Figure 4 To ensure horizontal scanning performance, the relative position of the camera output direction and the screen is usually as follows: Figure 4 As shown, the length of the captured original image Image corresponds to the length of the screen Screen, and the width corresponds to the width of the screen. This simplifies the coordinate conversion process during display and increases the display speed. It can be seen that the more pixels that need to be displayed, the longer the image processing time is, and it can be seen that not every part of the original image has the same importance. For code scanning preview, the optimal situation is that the barcode image is located in the center of the original image, so whether the image appears in the center is a special concern. On this basis, the content in the middle of the original image can be extracted. The cropping resolution is set here, that is, the cropping resolution is a pre-set resolution range that corresponds to the shooting resolution and is most likely to appear. Different cropping resolutions can be set according to the characteristics of the scanned image. For example, the present application Figure 4 In the example, the target is a QR code image, which is usually a square, and the best situation for scanning the code is that the QR code image appears completely in the center of the image. In this case, the cropping resolution can be set to 480*480, and the corresponding offset calculation method is (shooting resolution-cropping resolution) / 2. Correspondingly, if the image to be cropped is located in the middle of the original image, the offset needs to be calculated, that is, the starting position for cropping the original image. If the cropped image contains a complete QR code, it means that the scanning conditions are met. Because the width is the same, at this time, only the length (640-480) / 2=80 needs to be calculated. If the width offset needs to be calculated, the width calculation in the resolution is used. The amount of data that needs to be processed is reduced by cropping the original image; if the target is a barcode, such as a barcode with an aspect ratio of 2:1, the cropping resolution can be set to 320*160, and so on.

[0035] S130, cropping the original image according to the cropping resolution and the offset to obtain a first preview image; obtaining a starting position according to the offset, and starting to crop the length and width corresponding to the cropping resolution from the starting position. For example, if the offset is 80 pixels in length, then after offsetting 80 pixels from the length of the original image, start cropping a picture of 480 pixels in length and 480 pixels in width. If the offset includes the width, then both the length and the width need to be offset before acquisition.

[0036] S140, obtaining a screen preview resolution, where the screen preview resolution is smaller than the cropping resolution; wherein the screen preview resolution is a resolution of the preview image finally displayed;

[0037] In an optional implementation, the screen preview resolution is smaller than the screen resolution, which is the resolution of the screen of the code scanning device. For example, setting the screen preview resolution to 200*200 means that the resolution of the second preview image finally displayed on the screen is 200*200, which is smaller than the cropping resolution 480*480 and the screen resolution 320*240; this ensures that while further reducing the amount of data processing, it will not exceed the maximum display range of the screen and cause data loss.

[0038] S150, calculating a sampling interval according to the cropping resolution and the screen preview resolution, including:

[0039] The sampling interval is obtained according to the ratio of the cropping resolution to the screen preview resolution. For example, the sampling interval can be obtained by rounding down the ratio of the pixel value of the cropping resolution row to the pixel value of the screen resolution row, such as the sampling interval step = 480 / 200, because the number of pixels is only an integer. Then sampling is performed with a sampling interval of 2 on both rows and columns. In this way, compared with the method of directly scaling the full image taken by multiples, cropping first and then sampling can ensure the sampling effect while reducing the amount of data, and can uniformly sample the first preview image of the cropping resolution size into the second preview image of the screen preview resolution size; reduce the information loss in the first preview image during the sampling process. The existing interval sampling algorithm has been improved to a certain extent, thereby realizing the non-integer multiple reduction function to meet the preview requirements of the QR code.

[0040] S160: Sample the first preview image according to the sampling interval to obtain a second preview image, and display the second preview image on the screen.

[0041] In an optional implementation, step S160 also includes pixel matching steps S101-S102. In this way, when the image format captured by the camera is different from the image format displayed by the display, the format conversion formula is obtained, and the possible numerical correspondence is calculated in advance. Then, during the format conversion process, the numerical value in the captured image format can be directly matched with the calculated display image format, and the calculation result is calculated once in advance and then stored, saving subsequent calculation time.

[0042] S101, obtaining a conversion formula between a captured image format of a camera and a displayed image format of a display.

[0043] In an optional implementation, the image format captured by the camera is in YUV format, and the display image format is in RGB format, then the conversion formula includes:

[0044] R = Y + C × (V-128);

[0045] G = YD × (U-128) - E × (V-128);

[0046] B = Y + F × (U-128);

[0047] Wherein, A, B, C and D represent constants. In an optional implementation, C = 1.370705; D = 0.337633; E = 0.698001; F = 1.732446. Different values ​​of C, D, E and F can also be taken according to different accuracy requirements to meet the requirements of balancing accuracy and calculation speed under different devices.

[0048] In this way, the formula for converting the YUV format to the RGB format is obtained, which is convenient for subsequent direct calculation of the results of conversion to the RGB format corresponding to different YUV values ​​according to the formula, and is convenient for direct calling in the subsequent conversion process.

[0049] In an optional implementation, the conversion formula further includes:

[0050] Preset brightness boost variable iBriPara.

[0051] Y = Y' + iBriPara;

[0052] Where Y' represents the original brightness of the captured image, and Y represents the brightness of the captured image after optimization. Since the solution in this embodiment does not need to be supplemented by white light or red aiming light to confirm the position, the original image collected by the solution in this embodiment may be dark, thereby affecting the accuracy of the recognition result and the efficiency of recognition. Therefore, the brightness enhancement variable iBriPara is introduced here. In this way, the value of the brightness enhancement variable can be set according to the characteristics of the collected image, and the brightness compensation can be achieved without adding a fill light, thereby improving the quality of the image.

[0053] S102: Obtain a combination to be calculated that includes a single undetermined coefficient in the conversion formula, and assign values ​​to the undetermined coefficient in the combination to be calculated to obtain a result array corresponding to the combination to be calculated.

[0054] In an optional implementation, the process before S102 includes initializing global data for storing the result array:

[0055] static short__s_r_1370705v

[256] ={0};

[0056] static short__s_b_1732446u

[256] ={0};

[0057] static short__s_g_337633u

[256] ={0};

[0058] static short__s_g_698001v

[256] ={0};

[0059] In the formula, s_r_1370705v indicates that the calculation result of the combination to be calculated C×(V-128) is stored, and the representation of other global data is similar. Since it is known that the value range of UV is [0,255], which includes 256 integer values, the global data of the storage result array is initialized here and named in a way associated with the combination to be calculated, so as to facilitate the storage of data in the subsequent calculation result array.

[0060] In an optional embodiment, it includes:

[0061] S1021. Obtain the combinations to be calculated in the conversion formula: C×(V-128), D×(U-128), E×(V-128), and F×(U-128).

[0062] S1022. Obtain the value range of U and V [0,255].

[0063] In an optional implementation, if brightness enhancement is required, the value range of Y' is obtained as [0, 255].

[0064] S1023. Traverse the integer values ​​in the value range. When the target integer value is reached, use the target integer value to assign values ​​to the coefficients to be determined in the combinations to be calculated C×(V-128), D×(U-128), E×(V-128) and F×(U-128) to obtain the calculation results corresponding to each combination to be calculated.

[0065] In an optional implementation, if brightness enhancement is required, the method further includes assigning values ​​to undetermined coefficients in the calculation combination Y'+iBriPara when a target integer value is traversed to obtain a corresponding calculation result.

[0066] That is, when U is set to an integer value in [0,255], the corresponding calculation results of D×(U-128) and F×(U-128) are obtained; when V is set to an integer value in [0,255], the corresponding calculation results of C×(V-128) and E×(V-128) are obtained; when Y' is set to an integer value in [0,255], the corresponding calculation result of Y'+iBriPara is obtained, and 256 calculation results are obtained respectively.

[0067] S1024, storing calculation results according to different combinations to be calculated. In this way, the calculation results corresponding to different combinations to be calculated are stored separately, which facilitates the retrieval of calculation results during calculation and improves efficiency.

[0068] S1025, after the traversal is completed, the result array corresponding to each combination to be calculated is obtained. According to the steps in S1021 to S1025, the conversion formula is split into independent combinations to be calculated according to the coefficients to be determined, and each combination to be calculated includes only one coefficient to be determined. Then, by assigning the coefficients to be determined according to the value range of the coefficients to be determined, the corresponding value of the combination to be calculated can be uniquely obtained, thereby associating the assignment of the coefficients to be determined with the calculated value of the combination to be calculated. When the corresponding coefficients to be determined are obtained later, there is no need to repeat the calculation, and the calculated value with the calculated combination can be directly obtained, thereby omitting the calculation steps in the process of format conversion, and improving the efficiency of format conversion.

[0069] For example, it can be stored as:

[0070] __s_r_1370705v[i]=(1.370705*(i-128));

[0071] __s_b_1732446u[i]=(1.732446*(i-128));

[0072] __s_g_337633u[i]=(0.337633*(i-128));

[0073] __s_g_698001v[i]=(0.698001*(i-128));

[0074] The range of i is [0,255] in S1023, and the final storage is the calculation result. For example, when i=128, s_r_1370705v

[128] =0 is calculated, and 0 is stored as the 128th element of the array.

[0075] In an optional implementation, the subscript of an element in a result array is the same as the target integer corresponding to the element. In this way, the calculation result corresponding to the target integer can be found by searching the subscript of the array. There is no need to store the correspondence between the integer value and the calculation result in the array. Only the calculation result needs to be stored and the integer value needs to be recorded in the subscript, thereby saving storage space.

[0076] Please refer to Figure 3 , then step S160 includes:

[0077] S161. After sampling pixel points in the first preview image according to the sampling interval, the pixel points are used as pixel points in the second preview image; and a target result corresponding to the pixel points is searched in a result array.

[0078] In an optional implementation, the pixel points in the first preview image are sampled to obtain the collected pixel values ​​(u, v, y), and the array can be directly written into the conversion formula, and the conversion formula can be rewritten as follows:

[0079] r = y + __s_r_1370705v[v];

[0080] g=y-__s_g_337633u[u]-__s_g_698001v[v];

[0081] b = y + __s_b_1732446u[u];

[0082] In this way, the corresponding result array is directly searched according to the pixel point (u, v, y) in the first preview image to obtain the target result for display, the result array is pre-calculated and stored, and the target result is directly matched according to the parameters to be calculated in the actual calculation process, without the need for further calculation steps, thus avoiding the floating-point calculation process in each pixel conversion process.

[0083] S162, converting the pixels in the second preview image into a display image format according to the target result and the conversion formula and displaying the format, including:

[0084] S1611, each time a target result corresponding to a sampling point is obtained, the pixel value of the sampling point is converted into a display image format according to the target result and a conversion formula;

[0085] S1612: Determine whether the conversion of the preset number of sampling points is completed. If so, display the preset number of sampling points and reset the count of the sampling points.

[0086] According to the steps in S1611 and S1612, unlike the prior art method of displaying after completing the conversion of a frame of image, a preset number of configured sampling points are received and displayed after completing the conversion of the preset number of sampling points, which reduces the time difference between the process of acquiring the original image and displaying the second preview image on the screen, making the time when the second preview image is displayed on the screen closer to the time when the original image is acquired, thereby further improving the display efficiency. For example, it is possible to display the data of a pixel point after completing the sampling of a pixel point, without waiting for the data of a row of pixels to be fully converted or the data of a frame of pixels to be fully converted before displaying, thereby further reducing the delay of image display.

[0087] In an optional embodiment, the preset number is the number of pixels in one row of the cropping resolution. In this way, the conversion and display are not performed after the complete sampling of the second preview image is completed, but each pixel is converted during the sampling process, and the display is performed after the number of conversions reaches the preset number, which reduces the data stored in the memory and thus reduces the memory size requirements. Setting the preset number to the number of pixels in a row and displaying it row by row improves the display effect of the picture, and the sampling speed and display speed of the pixels are closer, further reducing the memory occupancy and avoiding the problem that the sampled pixels cannot be stored because the pixels in the memory have not been fully displayed or the pixels in the memory have been fully displayed but the new pixels have not been sampled.

[0088] In an optional implementation, S1612 includes: obtaining the number of sampling points of the current row, determining whether the number is equal to the number of pixels of a row of the screen preview resolution; if so, completing the conversion of sampling points of a row of captured images. In this way, during the sampling process, the position of the current sampling is determined, so that it can be determined in time whether the sampling of a row of pixels has been completed, so that the pixels that have been sampled can be displayed in time.

[0089] The following is a detailed description of the application embodiments of the present application. The present application can apply the above solution to electronic devices that require code scanning, such as POS terminals, especially simple POS terminals, and other financial payment terminals with code scanning and display functions. It includes steps (1)-(7)

[0090] (1) System initialization.

[0091] (2) Define and initialize the index array. Each combination to be calculated corresponds to an index array. The value of the index array subscript is the value of U, V or Y in the combination to be calculated. The value stored in the array element of the index array is the result value obtained by calculating the combination to be calculated based on the subscript U, V or Y.

[0092] (3) Configure the camera according to the code scanning requirements. After the user sets the screen preview resolution, screen display position and other information according to the display requirements, start the camera to collect images. The screen preview resolution is the resolution at which the image is finally displayed on the screen.

[0093] (4) Calculate the interval sampling step size according to the cropping resolution and the screen preview resolution; assuming that the cropping resolution is 480*480 and the screen preview resolution is 200*200, then calculate the interval sampling step size as 480 / 200 and round it down to 2 as the interval sampling step size. Calculate the starting offset according to the display requirements and select the corresponding sampling points in a loop. For example, if the display requirement is that a complete QR code appears in the center of the image, the offset is (shooting resolution-cropping resolution) / 2. For example, if the shooting resolution is 640*480, since the width is the same, the length only needs to be calculated as (640-480) / 2=80; after offsetting the image by the corresponding value, start to select the corresponding sampling points in a loop with the interval sampling step size.

[0094] (5) The RGB value corresponding to the YUV value of each pixel point is searched in the index array through the index method. Specifically, the calculation result of the corresponding combination to be calculated can be retrieved according to the YUV value, and then the RGB value is calculated. Since the floating-point calculation that consumes too much computing resources is stored in advance, the calculation time is reduced and the calculation efficiency is improved.

[0095] (6) Save the converted RBG values ​​of each line to be displayed, and send each line of data to the screen for display. Each line can be changed according to the memory size and latency requirements, for example, each time the RGB value of a pixel is converted, it is displayed, or the RGB value of a frame of pixels is converted before display, which is not limited here.

[0096] (7) Determine whether a frame of image has been displayed. If so, the preview of a frame ends. Otherwise, return to step (5).

[0097] In an optional embodiment, referring to Figure 3 :

[0098] a. After sampling starts, the sampling starting point is obtained by offsetting 80 pixels from the starting position according to the offset value, and the sampling interval of 2 pixels is obtained.

[0099] b. Traverse a row of data of the first preview image to determine whether it reaches the sampling starting point. If so, execute step c; otherwise, repeat step b.

[0100] c. Sampling a point from the sampling starting point, and searching the RGB value corresponding to the YUV value of the pixel point in the index array by the index method; after sampling a point, add the sampling interval and move to the next point for sampling; determine whether the sampling of a row of data is completed, and if so, send it for display.

[0101] d. Determine whether the sampling focus has been reached. If so, end the sampling; otherwise, return to step b.

[0102] Please refer to Figure 6The present invention also provides an electronic device 300, including a memory 301 and a processor 302, and a computer program stored in the memory 301 and running on the processor 302. When the processor 302 executes the computer program, each step in the above-mentioned code scanning preview method is implemented. The electronic device 300 can be a POS terminal, especially a simple POS terminal, and other financial payment terminals with code scanning and display functions.

[0103] For example Figure 5 It is a schematic diagram of a simple POS terminal, including a screen, a camera and a flash. A preview frame can be displayed on the screen, and a second preview image obtained by the above-mentioned code scanning preview method is displayed in the preview frame.

[0104] The beneficial effects of the electronic device of the present invention are the same as those of the above method and will not be described in detail here.

[0105] In summary, the present invention provides a code scanning preview method and electronic device. After the camera captures the original image, the offset is calculated according to the cropping resolution in the code scanning requirement and the shooting resolution of the original image, that is, the position that needs to be previewed can be set. For example, during the scanning process, the two-dimensional image usually needs to appear in the center of the screen, so the preset position can be set in the center of the original image. According to the position, the shooting resolution and the cropping resolution, the offset in the original image can be determined. According to the offset, the position where the cropping starts is determined and the cropping is performed according to the cropping resolution, so that the first preview image can be obtained. The first preview image corresponds to the image of the position that needs to be previewed in the original image. The position that needs to be previewed in the original image can be freely set by setting the offset and the cropping resolution. Further, after the amount of data to be processed is reduced by cropping the original image into the first preview image, the sampling interval is calculated according to the preset screen preview resolution, that is, the size of the image displayed on the screen and the cropping resolution; that is, the screen resolution does not match the first preview image, and other content may need to be displayed on the screen, and it is impossible to preview in full screen, so the first preview image is sampled according to the sampling interval according to the screen preview resolution set by the user, which reduces the amount of data to be processed when the final display is displayed, and improves the efficiency of the preview. And before sampling, in order to solve the problem that the format of the captured original image does not match the display format supported by the screen, the converted display format value corresponding to the value of each pixel in the original image format is pre-stored. Then, during the format conversion process, the saved converted value can be directly read according to the current value, eliminating the calculation process during the format conversion process and speeding up the preview efficiency. In addition, in accordance with the array storage method, the array subscript corresponds to the value in the original image format, and the value stored in the array is converted into the display format value. During the conversion process, the array content can be directly obtained according to the array subscript, and the pre-calculated result can be directly obtained, which further reduces the calculation time, improves the preview efficiency, and improves the user experience.

[0106] The above are only embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the specification and drawings of the present invention, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A code scanning preview method, characterized in that: Applied to a code scanning device, the code scanning device includes a screen, and the method includes: Obtaining a code scanning requirement, wherein the code scanning requirement includes a preset cropping resolution; Obtaining a shooting resolution of the original image shot by the camera, and calculating an offset according to the shooting resolution and the cropping resolution; Cropping the original image according to the cropping resolution and the offset to obtain a first preview image; Acquire a screen preview resolution, where the screen preview resolution is smaller than the cropping resolution; Calculate a sampling interval according to the cropping resolution and the screen preview resolution; The first preview image is sampled according to the sampling interval to obtain a second preview image, and the second preview image is displayed on the screen.

2. A code scanning preview method according to claim 1, characterized in that: The sampling interval calculated according to the cropping resolution and the screen preview resolution comprises: The sampling interval is obtained according to the ratio of the cropping resolution to the screen preview resolution.

3. A code scanning preview method according to claim 1, characterized in that: Before displaying the second preview image on the screen, the method further includes: Obtain the conversion formula between the image format captured by the camera and the image format displayed by the display; Acquire a combination to be calculated including a single coefficient to be determined in the conversion formula, and assign the coefficient to be determined in the combination to be calculated to obtain a result array corresponding to the combination to be calculated; Sampling the first preview image according to the sampling interval to obtain a second preview image, and displaying the second preview image on the screen comprises: After sampling the sampling points in the first preview image according to the sampling interval, the sampling points are used as pixel points in the second preview image; and the target result corresponding to the pixel point is searched in the result array; The pixels in the second preview image are converted into a display image format using the target result and the conversion formula, and the pixels in the second preview image in the display image format are displayed on the screen.

4. A code scanning preview method according to claim 3, characterized in that: The captured image format is in YUV format, and the displayed image format is in RGB format; The conversion formula between the image format captured by the camera and the image format displayed by the display includes: R = Y + C × (V-128); G = YD × (U-128) - E × (V-128); B = Y + F × (U-128); Among them, C, D, E and F represent constants; The obtaining of a combination to be calculated including a single undetermined coefficient in the conversion formula, and assigning the undetermined coefficient in the combination to be calculated to obtain a result array corresponding to the combination to be calculated includes: Obtain the combinations to be calculated C×(V-128), D×(U-128), E×(V-128), and F×(U-128) in the conversion formula; Get the value range of U and V [0,255]; Traversing the integer values ​​in the value range, when traversing to the target integer value, assigning the undetermined coefficients in the combinations to be calculated C×(V-128), D×(U-128), E×(V-128) and F×(U-128) with the target integer value, to obtain the calculation result corresponding to each combination to be calculated; storing the calculation results according to different combinations to be calculated; After the traversal is completed, a result array corresponding to each combination to be calculated is obtained.

5. A code scanning preview method according to claim 4, characterized in that: The subscripts of the elements in the result array are the same as the target integer values ​​corresponding to the elements.

6. A code scanning preview method according to claim 3, characterized in that: The conversion formula between the image format captured by the camera and the image format displayed by the display also includes: Preset brightness boost variable iBriPara; Y = Y' + iBriPara; Wherein, Y' represents the original brightness of the captured image, and Y represents the optimized brightness of the captured image.

7. A code scanning preview method according to claim 3, characterized in that: Sampling the first preview image according to the sampling interval to obtain a second preview image, and displaying the second preview image on the screen comprises: Each time the target result corresponding to the sampling point is obtained, the pixel value of the sampling point is converted into a display image format according to the target result and a conversion formula; It is determined whether the conversion of the preset number of sampling points is completed, and if so, the preset number of sampling points are displayed on the screen.

8. A code scanning preview method according to claim 7, characterized in that: The preset number is the number of pixels in one row of the cropping resolution.

9. A code scanning preview method according to claim 8, characterized in that: The step of determining whether the conversion of the preset number of sampling points is completed comprises: Obtain the number of sampling points in the current row, and determine whether the number is equal to the number of pixels in one row of the screen preview resolution; If so, the sampling point conversion of a row of captured images is completed.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, each step of the code scanning preview method described in any one of claims 1 to 9 is implemented.