Camera focusing method, device, equipment and readable storage medium
By analyzing the images acquired by the camera, building a three-dimensional model and determining the target focal length and focus coordinates of the camera, the problem of low accuracy in the traditional focusing method is solved and more efficient automatic focus is achieved.
Patent Information
- Application Number
- CN202211046535.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-29
- Publication Date
- 2025-05-06
- Estimated Expiration
- 2042-08-29
AI Technical Summary
The traditional camera focus method relies on manual experience, resulting in low accuracy when determining the focal length, and it is impossible to effectively match workpieces with irregular shapes and heights.
By reading the images collected by the camera, analyzing the offset coordinates and chromaticity of pixel points, building a three-dimensional model, determining the target focal length and focus coordinates of the camera, and using this to determine the target focus viewing angle to achieve automatic focus.
It improves the camera's focus accuracy, reduces the dependence on manual experience, can match workpieces of different shapes and heights more quickly and accurately, and improves machining efficiency.
Smart Images

Figure CN115589530B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of lasers, and in particular to a camera focusing method, device, equipment and readable storage medium. Background Art
[0002] With the widespread application of visual equipment in production processes, people's requirements for the automation level of visual equipment are getting higher and higher.
[0003] At present, automated laser equipment is equipped with a visual interface. When the equipment is laser cutting, marking, and welding workpieces, the camera focal length needs to be manually adjusted to match workpieces of different shapes and heights to obtain the best visual focal length because the shape of the product to be processed is irregular and there is a height difference. After obtaining a clear view of the workpiece, operate the motion device in the equipment to move to the position where processing is required for processing.
[0004] Since the traditional focusing method mainly relies on manual on-site adjustment of the camera's focal length, it is highly dependent on manual experience. However, since the level of manual experience varies, the accuracy of determining the camera's focal length is not high. Summary of the invention
[0005] In view of this, the present application provides a camera focusing method, device, equipment and readable storage medium, aiming to improve the focusing accuracy of the camera.
[0006] To achieve the above object, the present application provides a camera focusing method, the method comprising:
[0007] Reading a first image captured by a camera;
[0008] Determining a first target focal length and a first target focus coordinate of the camera based on the first image;
[0009] Based on the first target focal length and the first target focus coordinate, a target focus angle of view of the camera is determined so that the camera focuses at the target focus angle of view.
[0010] Exemplarily, determining a first target focal length and a first target focus coordinate of the camera based on the first image includes:
[0011] Analyze the first image to obtain offset coordinates of a plurality of pixel points in the first image and a chromaticity corresponding to each of the pixel points;
[0012] Constructing a three-dimensional model of the pixel based on the offset coordinates and the chromaticity, wherein the chromaticity is a Z coordinate in the three-dimensional model;
[0013] Based on the three-dimensional model, a first target focal length and a first target focus coordinate of the camera are determined.
[0014] Exemplarily, determining the first target focal length and the first target focus coordinate of the camera based on the three-dimensional model includes:
[0015] Based on the three-dimensional model, determining a first target focus coordinate corresponding to the average chromaticity of the pixel point;
[0016] The camera is moved to the first target focus coordinate, and a first target focal length of the camera is determined.
[0017] Exemplarily, determining the first target focus coordinate corresponding to the average chromaticity of the pixel point based on the three-dimensional model includes:
[0018] Based on the three-dimensional model, the pixel points are classified according to the chromaticity values of the chromaticity to obtain a plurality of pixel point categories with different chromaticity values;
[0019] Based on the discreteness of the pixel point categories, selecting a preset number of target pixel point categories from the pixel point categories;
[0020] The average value of the coordinates corresponding to each pixel point in the target pixel point category is calculated to obtain the first target focus coordinates.
[0021] Exemplarily, before selecting a preset number of target pixel point categories from the pixel point categories based on the discreteness of the pixel point categories, the method includes:
[0022] Counting the number of pixels in each of the pixel categories;
[0023] Based on the quantity, the pixel point categories are sorted to obtain a sequence of the pixel point categories.
[0024] Exemplarily, after determining the first target focal length and the first target focus coordinate of the camera based on the first image, the method further includes:
[0025] Reading a second image captured by the camera at the first target focal length and the first target focus coordinates;
[0026] Determining a second target focal length and a second target focus coordinate of the camera based on the second image;
[0027] Calculate the average target focal length for the cameras.
[0028] Exemplarily, after determining the target focus angle of the camera based on the first target focal length and the first target focus coordinate so that the camera focuses at the target focus angle, the method further includes:
[0029] storing the acquired image of the first workpiece and the corresponding target focus angle of view in a storage module;
[0030] When the image of the second workpiece is acquired, the image of the first workpiece is retrieved from the storage module and matched;
[0031] If the acquired image of the second workpiece matches the image of the first workpiece to a degree greater than or equal to a preset degree of matching, it is determined that the target focus angle of the second workpiece is the same as the target focus angle of the first workpiece.
[0032] Exemplarily, to achieve the above-mentioned purpose, the present application further provides a camera focusing device, the camera focusing device comprising:
[0033] A first reading module, used for reading a first image captured by a camera;
[0034] A first determination module, configured to determine a first target focal length and a first target focus coordinate of the camera based on the first image;
[0035] The second determination module is used to determine the target focus angle of the camera based on the first target focal length and the first target focus coordinate, so that the camera focuses at the target focus angle.
[0036] Exemplarily, to achieve the above-mentioned purpose, the present application also provides a camera focusing device, which includes a memory, a processor, and a camera focusing program stored in the memory and executable on the processor, and the camera focusing program implements the steps of the camera focusing method described above when executed by the processor.
[0037] Exemplarily, to achieve the above-mentioned purpose, the present application also provides a computer-readable storage medium, on which a camera focus program is stored, and when the camera focus program is executed by a processor, the steps of the camera focus method described above are implemented.
[0038] Compared with the prior art, the focal length of the camera is adjusted manually on site, which is highly dependent on manual experience. Due to the uneven level of manual experience, the accuracy of determining the focal length of the camera is not high. The present application reads a first image captured by a camera; based on the first image, determines a first target focal length and a first target focus coordinate of the camera; based on the first target focal length and the first target focus coordinate, determines the target focus angle of the camera, so that the camera can focus at the target focus angle. The present application avoids adjusting the focal length of the camera by manual experience with uneven levels, and instead uses a processing device to analyze the first image of the workpiece captured by the camera, accurately determines the focus coordinates and focal length of the workpiece, and further accurately determines the focus angle of the camera. Therefore, the present application improves the focusing accuracy of the camera. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0040] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0041] Figure 1 is a flowchart of the first embodiment of the camera focusing method of the present application;
[0042] Figure 2 is a schematic diagram of a pixel point coordinate system of the first embodiment of the camera focusing method of the present application;
[0043] Figure 3 is a schematic diagram of a chromaticity three-dimensional model of a first embodiment of the camera focusing method of the present application;
[0044] Figure 4 is a flowchart of the first embodiment of the camera focusing method of the present application;
[0045] Figure 5 It is a structural diagram of the hardware operating environment involved in the embodiment of the present application.
[0046] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0047] 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.
[0048] This application provides a camera focusing method, referring to Figure 1 , Figure 1 This is a flowchart diagram of the first embodiment of the camera focusing method of the present application.
[0049] The embodiments of the present application provide an embodiment of a camera focusing method. It should be noted that although a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than that shown here. For ease of description, the following omits the execution subject to describe the various steps of the camera focusing method, and the camera focusing method includes:
[0050] Step S10, reading a first image captured by a camera.
[0051] Step S20: determining a first target focal length and a first target focus coordinate of the camera based on the first image.
[0052] Step S30: determining a target focus angle of the camera based on the first target focal length and the first target focus coordinate, so that the camera focuses at the target focus angle.
[0053] The specific steps are as follows:
[0054] Step S10, reading a first image captured by a camera.
[0055] In this embodiment, the camera acquires an image and transmits the image projected onto the sensor through the lens to a processing device that can store, analyze and display it; the first image is an image of the workpiece acquired by the camera at an initial focal length at an initial position, wherein the image includes the complete workpiece.
[0056] Exemplarily, the initial focal length of the camera is set as required, and this embodiment does not specifically limit it. For example, the initial focal length of the camera can be 35mm, 50mm, 85mm, etc.
[0057] Exemplarily, the initial position of the camera collecting the first image is set as needed, and this embodiment does not specifically limit it. For example, the initial position of the camera collecting the first image is projected on the center of the workpiece.
[0058] Exemplarily, the camera includes a CCD camera and a CMOS camera. Furthermore, the camera includes a line scan camera or a high-speed acquisition array camera (a high-speed acquisition array camera uses a high-magnification telecentric lens when acquiring dispensing images). It should be noted that the present application generally uses a high-speed acquisition array camera instead of a line scan camera when acquiring the first image because, compared to a line scan camera, a high-speed acquisition array camera has the advantages of high frame rate and high precision, and can obtain a clearer first image of the workpiece, further improving the accuracy of the first image in determining the focal length and focus coordinates during detection.
[0059] Specifically, the camera first captures the workpiece image at the initial position with the initial focal length to obtain a scanned image of the workpiece on the carrier plane. The processing device uses the file reading function inf.read((char*)m_pImageData,m_iImageDataSize) of WINAPI (Windows Operating System Application Programming Interface) to obtain the first image containing the complete workpiece image captured by the camera, and analyzes the first image to determine the focal length and focus coordinates of the camera. The first image can be an image of the workpiece that has been captured historically by the camera and stored in the processing device, or it can be an image of the workpiece that has been captured in real time by the camera.
[0060] Step S20: determining a first target focal length and a first target focus coordinate of the camera based on the first image.
[0061] In this embodiment, the first target focus coordinate is the best focus coordinate for capturing the workpiece image determined by the processing device after analyzing the first image; the first target focal length is the best focal length for the camera to capture the workpiece image when the camera is at the first target focus coordinate. The processing device processes the first image to determine the first target focal length and the first target focus coordinate of the camera.
[0062] It can be understood that, due to the irregular shape and height differences of the workpiece, the height at which the camera captures the image is usually the average height of the workpiece.
[0063] Exemplarily, determining a first target focal length and a first target focus coordinate of the camera based on the first image includes:
[0064] Step S21, parsing the first image to obtain offset coordinates of a plurality of pixel points in the first image and the chromaticity corresponding to each of the pixel points.
[0065] In this embodiment, the pixel point is the smallest light-emitting unit in the first image, and the offset coordinates of the pixel point are the pixel coordinates in the image, where Figure 2 The origin of the pixel coordinate system uv is shown as O 0 , the horizontal coordinate u is the row where the pixel is located, and the vertical coordinate v is the column where the pixel is located. In the visual processing library, u corresponds to x and v corresponds to y.
[0066] Among them, chromaticity is the property of color excluding brightness, which reflects the hue and saturation of the color. If two points in the workpiece are at the same height, the chromaticity of the corresponding pixels in the image is the same or similar.
[0067] The specific steps of obtaining the offset coordinates (X, Y) of each pixel of the entire image and the corresponding RGB value by reading the storage format of the input BMP bitmap include:
[0068] 0x0000: File identifier 2Bytes The two-byte content is used to identify the type of bitmap;
[0069] 0x0002: File Size 1DWORD The size of the entire file in bytes;
[0070] 0x0006: Reserved 1DWORD reserved, must be set to 0;
[0071] 0x000A: Bitmap Data Offset 1DWORD The offset between the start of the file and the start of the bitmap data (Bitmap Data);
[0072] 0x000E: Bitmap Header Size, the length of the bitmap information header, used to describe the bitmap's color, compression method, etc.
[0073] Exemplarily, the types of bitmaps include: BMP (Bitmap) format, PNG (Portable Network Graphics) format, JPEG (Joint Photographic Experts Group) format. After identifying the type of the bitmap, the offset of the pixel point is determined according to the type of the bitmap, and then the offset coordinates of the pixel point are determined. This embodiment uses the BMP format for parsing, and the parsing steps of bitmaps in other formats are similar and will not be repeated.
[0074] Specifically, the acquired first image is parsed to determine the offset coordinates and the corresponding chromaticity of each pixel in the first image.
[0075] Step S22: constructing a three-dimensional model of the pixel based on the offset coordinates and the chromaticity, wherein the chromaticity is the Z coordinate in the three-dimensional model.
[0076] In this embodiment, the abscissa of the three-dimensional model is the abscissa of the pixel point, the ordinate is the ordinate of the pixel point, and the height is the chromaticity value of the chromaticity corresponding to the pixel point.
[0077] Specifically, save the offset coordinates (X, Y) of the pixel point as a vector <cpoint>, save the RGB value corresponding to the pixel point, that is, the chromaticity value as a vector<RGB(Value RGB)> , create a map corresponding to the offset coordinates and RGB values<CPOINT,RGB(Value RGB)> These three STL (Standard Template Library) containers correspond to the data types and store them. Figure 3 As shown, according to map<CPOINT,RGB(Value RGB)> A three-dimensional model is established, the pixel coordinates correspond to the X and Y coordinates of the three-dimensional model, and the chromaticity of the pixel corresponds to the Z coordinate of the three-dimensional model.
[0078] Step S23: determining a first target focal length and a first target focusing coordinate of the camera based on the three-dimensional model.
[0079] In this embodiment, the coordinates corresponding to the average chromaticity, ie, the first target focus coordinates of the camera, are calculated according to the three-dimensional model, and the first target focal length at the first target focus coordinates is determined.
[0080] Exemplarily, determining the first target focal length and the first target focus coordinate of the camera based on the three-dimensional model includes:
[0081] Step S231: determining a first target focus coordinate corresponding to the average chromaticity of the pixel point based on the three-dimensional model.
[0082] In this embodiment, the first target focus coordinate is the coordinate corresponding to the average chromaticity of the pixel point. It can be understood that since the chromaticity of the pixels corresponding to the same height point of the workpiece is similar or the same, the average chromaticity is the average height of the workpiece.
[0083] like Figure 4 FIG. 1 is a flow chart of the first embodiment of the camera focusing method of the present application.
[0084] Exemplarily, determining the first target focus coordinate corresponding to the average chromaticity of the pixel point based on the three-dimensional model includes:
[0085] Step S2311, based on the three-dimensional model, classify the pixel points according to the chromaticity value of the chromaticity to obtain a plurality of pixel point categories with different chromaticity values.
[0086] In this embodiment, the same pixel point category includes one or more pixel points with the same chromaticity value, which means that the pixel points in the same pixel point category are at the same height or a similar height of the workpiece.
[0087] Specifically, analyze vector<RGB(ValueRGB)> All the chromaticity values in it, merge the pixels with the same chromaticity value into the same category and store them in the map<RGB(ValueRGB),Count> , multiple pixel categories with different chromaticity values are obtained, and each category is a set of pixel points.
[0088] Step S2314: selecting a preset number of target pixel point categories from the pixel point categories based on the discreteness of the pixel point categories.
[0089] In this embodiment, the pixel point categories are arranged in ascending or descending order according to the number of pixels they contain. If the sorting method is ascending order, the higher the order of the pixel point category, the higher the discreteness; if the order of the pixel point category is later, the lower the discreteness. The target pixel point category is the category with high discreteness in the sequence selected by the operator from the pixel point category.
[0090] Exemplarily, the preset number of target pixel point categories is set as needed, and this embodiment does not specifically limit it. For example, 5 target pixel point categories, 6 target pixel point categories, and 10 target pixel point categories are selected. Among them, the more target pixel point categories are selected, the higher the focusing accuracy of the camera.
[0091] Exemplarily, before selecting a preset number of target pixel point categories from the pixel point categories based on the discreteness of the pixel point categories, the method includes:
[0092] Step S2312, counting the number of pixels in each of the pixel categories.
[0093] In this embodiment, the processing device counts the number of pixels in each pixel category. For example, the number of pixels in pixel category A is 1000, the number of pixels in pixel category B is 1200, and the number of pixels in pixel category C is 1500.
[0094] Step S2313: sort the pixel point categories based on the quantity to obtain a sequence of the pixel point categories.
[0095] In this embodiment, the pixel categories are sorted according to the number of pixels in each pixel category to obtain a sequence of pixel categories. The sorting method is descending order or ascending order. For example, the pixel categories are sorted in ascending order, and the number of pixels in pixel categories A, B, C, D, and E is 1000, 2000, 1500, 1800, and 3000 respectively, then the arrangement order is pixel category A, C, D, B, and E.
[0096] Step S2315, calculating the average value of the coordinates corresponding to each pixel point in the target pixel point category to obtain the first target focus coordinates.
[0097] In this embodiment, the average value of the offset coordinates of all the pixels included in the target pixel category is calculated, that is, the coordinates of the average chromaticity of the workpiece, that is, the first target focusing coordinates, are obtained.
[0098] Specifically, the selected RGB (ValueRGB) and map<CPOINT,RGB> The CPOINT values in the container are matched, and all the matched CPOINT values are stored in the CPOINT array. The average values of X and Y in the array are calculated to obtain the first target focus coordinate. For example, the pixel coordinates in target pixel point category A include (0,1)(1,1)(2,1), and the pixel coordinates in target pixel point category B include (0,10)(1,10)(2,10), then the first target focus coordinate is (1,11).
[0099] Step S232, moving the camera to the first target focusing coordinates, and determining the first target focal length of the camera.
[0100] In this embodiment, after the processing device obtains the first target focus coordinate, it issues a control instruction to control the camera to move to the first target focus coordinate. When the camera moves to the first target focus coordinate, automatic focusing can be performed, and the processing device obtains the focal length of the camera at the first target focus coordinate, that is, the first target focal length.
[0101] Exemplarily, after determining the first target focal length and the first target focus coordinate of the camera based on the first image, the method further includes:
[0102] Step a: reading a second image captured by the camera at the first target focal length and the first target focus coordinates.
[0103] In this embodiment, when the camera is at the first target focus coordinate, it captures an image of the workpiece at the first target focal length to obtain a second image, and transmits it to a processing device so that the processing device can determine the camera's second target focal length and second target focus coordinate based on the second image.
[0104] Step b: determining a second target focal length and a second target focusing coordinate of the camera based on the second image.
[0105] In this embodiment, the method by which the processing device processes the second image to obtain the second target focal length and second target focus coordinates of the camera is basically the same as the method by which the processing device processes the first image to obtain the first target focal length and first target focus coordinates of the camera, and will not be repeated in this embodiment.
[0106] Step c, calculating the average target focal length of the camera.
[0107] In this embodiment, the average target focal length is the average of multiple target focal lengths. For example, if the first target focal length is 35 mm, the second target focal length is 40 mm, and the third target focal length is 45 mm, then the average target focal length is 40 mm.
[0108] After determining the target focal length for the first time, the present application can optimize the focal length of the camera again according to the image captured at the target focal length, thereby further improving the focusing accuracy of the camera, and the accuracy increases with the increase in the number of optimization times.
[0109] Step S30: determining a target focus angle of the camera based on the first target focal length and the first target focus coordinate, so that the camera focuses at the target focus angle.
[0110] In this embodiment, when the focus is clear, the vertex angle of the angle between the center point of the lens and the diagonal line of the focal plane is the target focus angle of the lens. The focus angle is inversely proportional to the focal length. The shorter the focal length, the larger the focus angle; the longer the focal length, the smaller the focus angle. The proportional relationship between the focus angle and focal length of different cameras varies.
[0111] Specifically, the target focal length is calculated according to the target focus coordinates, and the target focus angle of the camera is determined according to the target focal length. If only one image is acquired to obtain a first target focal length, the target focus angle is determined according to the first target focal length; if multiple images are acquired, the average focal length of multiple target focal lengths is calculated, and the target focus angle is determined according to the average focal length.
[0112] Compared to manually adjusting the camera focal length to match workpieces of different shapes and heights to obtain the best focus focal length, and after obtaining a clear view of the workpiece, operating the motion device in the equipment according to the purpose, moving to the position where processing is required, and performing processing, while manually operating the motion device of the equipment takes a long time, the present application processes the workpiece through a camera and processing equipment to obtain the best focus focal length, thereby improving the efficiency of focusing and processing.
[0113] Exemplarily, after determining the target focus angle of the camera based on the first target focal length and the first target focus coordinate so that the camera focuses at the target focus angle, the method further includes:
[0114] Step d, storing the acquired image of the first workpiece and the corresponding target focus angle of view in a storage module;
[0115] Step e, when the image of the second workpiece is acquired, the image of the first workpiece is retrieved from the storage module and matched;
[0116] Step f: if the acquired image of the second workpiece and the image of the first workpiece have a matching degree greater than or equal to a preset matching degree, determining that the target focusing angle of the second workpiece is the same as the target focusing angle of the first workpiece.
[0117] In this embodiment, after determining the target focus angle of workpiece A, the current visual operation parameters and motion operation parameters can be integrated into a functional template and stored in the storage module. When the camera captures the image of workpiece B and transmits it to the processing device, the processing device retrieves all images of workpiece A from the storage module. If the shape matching degree of workpiece B and workpiece A is higher than the preset matching degree, it is determined that the target focus angles of workpiece B and workpiece A are the same, and the current visual operation parameters and motion operation parameters are used for focusing, thereby improving the focusing efficiency. Among them, the preset matching degree is set as needed, and this embodiment does not make specific limitations. For example, the preset matching degree is 90%, 95%, and 98%.
[0118] This application uses cameras and processing equipment to perform fast and accurate focusing, saving labor costs and improving the economy of focusing.
[0119] Compared with the prior art, the focal length of the camera is adjusted manually on site, which is highly dependent on manual experience. Due to the uneven level of manual experience, the accuracy of determining the focal length of the camera is not high. The present application reads a first image captured by a camera; based on the first image, determines a first target focal length and a first target focus coordinate of the camera; based on the first target focal length and the first target focus coordinate, determines the target focus angle of the camera, so that the camera can focus at the target focus angle. The present application avoids adjusting the focal length of the camera by manual experience with uneven levels, and instead uses a processing device to analyze the first image of the workpiece captured by the camera, accurately determines the focus coordinates and focal length of the workpiece, and further accurately determines the focus angle of the camera. Therefore, the present application improves the focusing accuracy of the camera.
[0120] Exemplarily, the present application also provides a camera focusing device, the camera focusing device comprising:
[0121] A first reading module, used for reading a first image captured by a camera;
[0122] A first determination module, configured to determine a first target focal length and a first target focus coordinate of the camera based on the first image;
[0123] The second determination module is used to determine the target focus angle of the camera based on the first target focal length and the first target focus coordinate, so that the camera focuses at the target focus angle.
[0124] Exemplarily, the second determining module includes:
[0125] A parsing submodule, used for parsing the first image to obtain offset coordinates of a plurality of pixel points in the first image and a chromaticity corresponding to each of the pixel points;
[0126] A construction submodule, configured to construct a three-dimensional model of the pixel point based on the offset coordinates and the chromaticity, wherein the chromaticity is a Z coordinate in the three-dimensional model;
[0127] The determination submodule is used to determine a first target focal length and a first target focus coordinate of the camera based on the three-dimensional model.
[0128] Exemplarily, the determining submodule includes:
[0129] A determination unit, configured to determine, based on the three-dimensional model, a first target focus coordinate corresponding to the average chromaticity of the pixel point;
[0130] A moving unit is used to move the camera to the first target focusing coordinate and determine a first target focal length of the camera.
[0131] Exemplarily, the determining unit includes:
[0132] A classification subunit, configured to classify the pixel points according to the chromaticity values of the chromaticity based on the three-dimensional model, to obtain a plurality of pixel point categories with different chromaticity values;
[0133] A selection subunit, configured to select a preset number of target pixel point categories from the pixel point categories based on the discreteness of the pixel point categories;
[0134] The calculation subunit is used to calculate the average value of the coordinates corresponding to each pixel point in the target pixel point category to obtain the first target focus coordinates.
[0135] Exemplarily, the determining unit further includes:
[0136] A counting subunit, used for counting the number of pixels in each pixel category;
[0137] A sorting subunit is used to sort the pixel point categories based on the quantity to obtain a sequence of the pixel point categories.
[0138] Exemplarily, the camera focusing device further includes:
[0139] A second reading module, used for reading a second image captured by the camera at the first target focal length and the first target focus coordinate;
[0140] A third determination module, configured to determine a second target focal length and a second target focus coordinate of the camera based on the second image;
[0141] A calculation module is used to calculate the average target focal length of the camera.
[0142] Exemplarily, the camera focusing device further includes:
[0143] A storage module, used to store the acquired image of the first workpiece and the corresponding target focus angle of view in the storage module;
[0144] a matching module, configured to retrieve the image of the first workpiece from the storage module and perform matching when acquiring the image of the second workpiece;
[0145] The fourth determination module is configured to determine that the target focus angle of the second workpiece is the same as the target focus angle of the first workpiece if the degree of match between the acquired image of the second workpiece and the image of the first workpiece is greater than or equal to a preset degree of match.
[0146] The specific implementation of the camera focusing device of the present application is basically the same as the embodiments of the camera focusing method described above, and will not be repeated here.
[0147] In addition, the present application also provides a camera focusing device. Figure 5 As shown, Figure 5 It is a structural diagram of the hardware operating environment involved in the embodiment of the present application.
[0148] For example, Figure 5 This is a structural diagram of the hardware operating environment of the camera focus device.
[0149] like Figure 5 As shown, the camera focusing device may include a processor 501, a communication interface 502, a memory 503 and a communication bus 504, wherein the processor 501, the communication interface 502 and the memory 503 communicate with each other via the communication bus 504, the memory 503 is used to store computer programs; the processor A01 is used to implement the steps of the camera focusing method when executing the program stored in the memory 503.
[0150] The communication bus 504 mentioned in the above camera focusing device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus 504 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, 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.
[0151] The communication interface 502 is used for communication between the camera focusing device and other devices.
[0152] The memory 503 may include a random access memory (Random Access Memory, RMD), or a non-volatile memory (Non-Volatile Memory, NM), such as at least one disk memory. Optionally, the memory 503 may also be at least one storage device located away from the processor 501.
[0153] The above-mentioned processor 501 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0154] The specific implementation of the camera focusing device of the present application is basically the same as the embodiments of the above-mentioned camera focusing method, and will not be repeated here.
[0155] In addition, an embodiment of the present application further provides a computer-readable storage medium, on which a camera focus program is stored. When the camera focus program is executed by a processor, the steps of the camera focus method described above are implemented.
[0156] The specific implementation of the computer-readable storage medium of the present application is basically the same as the above-mentioned camera focusing method embodiments, and will not be repeated here.
[0157] It should be noted that, in this article, the term "includes", "comprising" or any other variation thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0158] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0159] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, device, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0160] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.< / cpoint>
Claims
1. A camera focusing method, characterized in that: The method comprises: Reading a first image captured by a camera; Analyze the first image to obtain offset coordinates of a plurality of pixel points in the first image and a chromaticity corresponding to each of the pixel points; Constructing a three-dimensional model of the pixel based on the offset coordinates and the chromaticity, wherein the chromaticity is a Z coordinate in the three-dimensional model; Based on the three-dimensional model, the pixel points are classified according to the chromaticity values of the chromaticity to obtain a plurality of pixel point categories with different chromaticity values; Based on the discreteness of the pixel point categories, selecting a preset number of target pixel point categories from the pixel point categories; Calculate the average value of the coordinates corresponding to each pixel point in the target pixel point category to obtain the first target focus coordinates; Moving the camera to the first target focus coordinates and determining a first target focal length of the camera; Based on the first target focal length and the first target focus coordinate, a target focus angle of view of the camera is determined so that the camera focuses at the target focus angle of view.
2. The method according to claim 1, characterized in that Before selecting a preset number of target pixel point categories from the pixel point categories based on the discreteness of the pixel point categories, the method includes: Counting the number of pixels in each of the pixel categories; Based on the quantity, the pixel point categories are sorted to obtain a sequence of the pixel point categories.
3. The method according to claim 1, characterized in that After moving the camera to the first target focus coordinate and determining the first target focal length of the camera, the method further comprises: Reading a second image captured by the camera at the first target focal length and the first target focus coordinates; Determining a second target focal length and a second target focus coordinate of the camera based on the second image; Calculate the average target focal length for the cameras.
4. The method according to claim 1, characterized in that After determining the target focus angle of the camera based on the first target focal length and the first target focus coordinate so that the camera focuses at the target focus angle, the method further comprises: storing the acquired image of the first workpiece and the corresponding target focus angle of view in a storage module; When the image of the second workpiece is acquired, the image of the first workpiece is retrieved from the storage module and matched; If the acquired image of the second workpiece matches the image of the first workpiece to a degree greater than or equal to a preset degree of matching, it is determined that the target focus angle of the second workpiece is the same as the target focus angle of the first workpiece.
5. A camera focusing device, characterized in that: The device comprises: A first reading module, used for reading a first image captured by a camera; A parsing submodule, used for parsing the first image to obtain offset coordinates of a plurality of pixel points in the first image and a chromaticity corresponding to each of the pixel points; A construction submodule, configured to construct a three-dimensional model of the pixel point based on the offset coordinates and the chromaticity, wherein the chromaticity is a Z coordinate in the three-dimensional model; A classification subunit, configured to classify the pixel points according to the chromaticity values of the chromaticity based on the three-dimensional model, to obtain a plurality of pixel point categories with different chromaticity values; A selection subunit, configured to select a preset number of target pixel point categories from the pixel point categories based on the discreteness of the pixel point categories; A calculation subunit, used to calculate the average value of the coordinates corresponding to each pixel point in the target pixel point category to obtain a first target focus coordinate; A moving unit, used for moving the camera to the first target focusing coordinates and determining a first target focal length of the camera; The second determination module is used to determine the target focus angle of the camera based on the first target focal length and the first target focus coordinate, so that the camera focuses at the target focus angle.
6. A camera focusing device, characterized in that: The camera focusing device comprises a memory, a processor and a camera focusing program stored in the memory and executable on the processor, wherein the camera focusing program implements the steps of the camera focusing method according to any one of claims 1 to 4 when executed by the processor.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a camera focus program, and when the camera focus program is executed by a processor, the steps of the camera focus method according to any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Spectral confocal displacement sensor ranging calculation method, system and device and storage medium
CN112230236A
Brightness and chrominance data extraction method and device and computer readable storage medium
CN112687231A