Ranging method and apparatus, electronic device, and storage medium
By processing grayscale and contour information of images using machine vision technology, the problems of low accuracy and efficiency in traditional distance measurement methods are solved, achieving high-precision and high-efficiency distance measurement.
Patent Information
- Application Number
- CN202211717681.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-29
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2042-12-29
AI Technical Summary
Traditional methods of measuring workpiece distances rely on tools such as rulers and vernier calipers or manual visual inspection, resulting in low measurement accuracy and efficiency, which cannot meet the needs of modern enterprises for high precision and high efficiency.
Machine vision technology is used to perform binarization of image grayscale and contour information, and morphological operations are performed to extract distance information of the region to be measured.
It improves the accuracy and efficiency of distance measurement, enabling more accurate acquisition of distance information for the area to be measured.
Smart Images

Figure CN116147495B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the technical field of machine vision, and particularly relates to a distance measurement method and device, an electronic device and a storage medium. BACKGROUND
[0002] An important application scenario of machine vision detection is to measure distance information of a workpiece. Traditional measurement methods often need to use tools such as a ruler, a vernier caliper, a micrometer or a microscope to measure distance. Some scenes with low precision requirements directly use manual visual inspection. The measurement precision and efficiency of tool measurement and manual visual inspection are relatively low, and cannot meet the requirements of enterprises for higher and higher precision and efficiency. SUMMARY
[0003] The present application aims to at least solve one of the technical problems existing in the prior art. To this end, the present application provides a distance measurement method and device, an electronic device and a storage medium, which can improve the precision and efficiency of distance measurement by measuring distance through machine vision.
[0004] In a first aspect, the present application provides a distance measurement method, which comprises:
[0005] obtaining a first region image of a region to be measured;
[0006] obtaining a first binary image corresponding to the first region image based on the gray scale information and the contour information of the first region image;
[0007] performing morphological processing on the first binary image to obtain a second binary image;
[0008] obtaining distance information of the region to be measured based on the second binary image.
[0009] According to the distance measurement method of the present application, the image of the region to be measured is binarized based on the gray scale information and the contour information of the region to be measured, and morphological operation is performed on the binarized image to obtain the distance information of the region to be measured. The precision and efficiency of distance measurement are effectively improved by measuring distance through machine vision.
[0010] According to one embodiment of the present application, the first binary image corresponding to the first region image is obtained based on the gray scale information and the contour information of the first region image, which comprises:
[0011] In a case where the gray scale uniformity of the region to be measured is greater than a uniformity threshold and the contour complexity of the region to be measured is less than a complexity threshold based on the gray scale information and the contour information of the first region image, the first region image is binarized to obtain the first binary image.
[0012] According to one embodiment of the present application, the first binary image corresponding to the first region image is obtained based on the grayscale information and the contour information of the first region image, comprising:
[0013] In a case where the grayscale uniformity of the to-be-ranged region is not greater than a uniformity threshold and the contour complexity of the to-be-ranged region is not less than a complexity threshold based on the grayscale information and the contour information of the first region image, the first region image is subjected to convolution operation to obtain a first real-type gradient image;
[0014] The first real-type gradient image is subjected to image data format conversion to obtain a first byte-type gradient image;
[0015] The first byte-type gradient image is subjected to binaryzation processing to obtain the first binary image.
[0016] According to one embodiment of the present application, the first byte-type gradient image is obtained by subjecting the first real-type gradient image to image data format conversion, comprising:
[0017] The first real-type gradient image is subjected to absolute value processing and normalization processing in sequence;
[0018] The grayscale range of the first real-type gradient image after the absolute value processing and the normalization processing is adjusted to a target grayscale range, and the image data format conversion is performed to obtain the first byte-type gradient image;
[0019] The target grayscale range is a pixel value range corresponding to the first byte-type gradient image.
[0020] According to one embodiment of the present application, the second binary image is obtained by subjecting the first binary image to morphological processing, comprising:
[0021] The first binary image is subjected to morphological opening operation along a first direction and morphological closing operation along a direction perpendicular to the first direction, and the to-be-ranged region is extracted to obtain the second binary image;
[0022] The first direction is perpendicular to the distance measurement direction of the to-be-ranged region.
[0023] According to one embodiment of the present application, the distance information of the to-be-ranged region is obtained based on the second binary image, comprising:
[0024] The to-be-ranged region in the second binary image is subjected to Blob analysis and circumscribed slanting rectangle calculation to obtain the distance information of the to-be-ranged region.
[0025] In a second aspect, the present application provides a ranging device, comprising:
[0026] an acquisition module, configured to acquire a first region image of a region to be ranged;
[0027] a first processing module, configured to acquire a first binarization image corresponding to the first region image based on grayscale information and contour information of the first region image;
[0028] a second processing module, configured to perform morphological processing on the first binarization image to obtain a second binarization image;
[0029] a third processing module, configured to obtain distance information of the region to be ranged based on the second binarization image.
[0030] According to the ranging device provided by the present application, the image of the region to be ranged is binarized based on the grayscale information and contour information of the region to be ranged, and the binarization image is subjected to morphological operation to obtain the distance information of the region to be ranged, so that the distance is measured by machine vision, and the accuracy and efficiency of distance measurement are effectively improved.
[0031] In a third aspect, the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the ranging method according to the first aspect.
[0032] In a fourth aspect, the present application provides a non-transitory computer readable storage medium, having a computer program stored thereon, wherein the computer program is executable by a processor to implement the ranging method according to the first aspect.
[0033] In a fifth aspect, the present application provides a computer program product, comprising a computer program, wherein the computer program is executable by a processor to implement the ranging method according to the first aspect.
[0034] Additional aspects and advantages of the present application will be in part apparent and in part pointed out hereinafter. BRIEF DESCRIPTION OF DRAWINGS
[0035] The above and / or additional aspects and advantages of the present application will become apparent and be readily appreciated from the following description, including the appended drawings.
[0036] Figure 1 is one of the flowcharts of the ranging method provided by the embodiments of the present application;
[0037] Figure 2This is a second schematic flowchart of the ranging method provided in the embodiments of this application;
[0038] Figure 3 This is one of the schematic diagrams of the ranging examples provided in the embodiments of this application;
[0039] Figure 4 This is a second schematic diagram of a ranging example provided in the embodiments of this application;
[0040] Figure 5 This is the third schematic diagram of the ranging example provided in the embodiments of this application;
[0041] Figure 6 This is a schematic diagram of the first distance-to-be-measured area provided in an embodiment of this application;
[0042] Figure 7 This is a schematic diagram of the first distance-to-be-measured region after smoothing, provided in an embodiment of this application.
[0043] Figure 8 This is a schematic diagram of the first binarized image corresponding to the first distance-to-be-measured region provided in the embodiments of this application;
[0044] Figure 9 This is a schematic diagram of the second binarized image corresponding to the first distance-to-be-measured region provided in the embodiments of this application;
[0045] Figure 10 This is a schematic diagram of the second distance measurement area provided in the embodiments of this application;
[0046] Figure 11 This is a schematic diagram of the second distance-to-be-measured region after smoothing, provided in an embodiment of this application.
[0047] Figure 12 It is the first byte type gradient image corresponding to the second ranging region provided in the embodiments of this application;
[0048] Figure 13 This is a schematic diagram of the first binarized image corresponding to the second distance-to-be-measured region provided in the embodiments of this application;
[0049] Figure 14 This is a schematic diagram of the second binarized image corresponding to the second distance-to-be-measured region provided in the embodiments of this application;
[0050] Figure 15 This is a schematic diagram of the structure of the ranging device provided in the embodiments of this application;
[0051] Figure 16 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0052] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.
[0053] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0054] The ranging method, ranging device, electronic device, and readable storage medium provided in this application will be described in detail below with reference to the accompanying drawings and through specific embodiments and application scenarios.
[0055] The ranging method can be applied to the terminal, and can be executed by the hardware or software in the terminal.
[0056] The terminal includes, but is not limited to, portable communication devices such as mobile phones or tablets with touch-sensitive surfaces (e.g., touchscreen displays and / or touchpads). It should also be understood that, in some embodiments, the terminal may not be a portable communication device, but rather a desktop computer with touch-sensitive surfaces (e.g., touchscreen displays and / or touchpads).
[0057] The following embodiments describe a terminal including a display and a touch-sensitive surface. However, it should be understood that the terminal may include one or more other physical user interface devices such as a physical keyboard, mouse, and joystick.
[0058] The ranging method provided in this application embodiment can be executed by an electronic device or a functional module or entity in an electronic device that can implement the ranging method. The electronic devices mentioned in this application embodiment include, but are not limited to, mobile phones, tablets, computers, cameras, and wearable devices. The ranging method provided in this application embodiment is described below using an electronic device as the execution subject.
[0059] like Figure 1 As shown, the ranging method includes steps 110 to 140.
[0060] Step 110: Obtain the first region image of the area to be measured.
[0061] In practice, an industrial camera can be used to capture a first-area image of the area to be measured, and this first-area image can be a grayscale image.
[0062] The area to be measured can be a region on a certain contour of the workpiece, or it can be a region between two contours of the workpiece.
[0063] For example, such as Figure 3 As shown, the area to be measured can be the region between two contours of the workpiece.
[0064] For example, such as Figure 4 and Figure 5 As shown, the area to be measured can be a region on a certain contour of the workpiece. By measuring the distance of the area to be measured, it can be determined whether the workpiece is a defective (NG) or good (OK) product.
[0065] In this step, a first region image of the area to be measured is obtained, and the first region image can be smoothed to remove image noise interference.
[0066] Step 120: Based on the grayscale information and contour information of the first region image, obtain the first binarized image corresponding to the first region image.
[0067] Based on the grayscale and contour information of the first region image, the grayscale uniformity and contour complexity of the region to be measured are determined. Different operations are performed on the first region image for different types of regions to be measured to obtain the first binarized image corresponding to the first region image.
[0068] Image binarization is the process of setting the grayscale value of pixels in an image to 0 or 255, thus giving the entire image a distinct black and white effect.
[0069] The first binarized image obtained by digital image processing can greatly reduce the amount of data in the first region image, thereby highlighting the outline of the region to be measured and helping to improve the accuracy of distance measurement in the region to be measured.
[0070] Step 130: Perform morphological processing on the first binarized image to obtain the second binarized image.
[0071] In this embodiment, morphological processing is performed on the first binarized image to extract the shape of the region to be measured in the first binarized image, so as to further measure the distance of the region to be measured.
[0072] Step 140: Based on the second binarized image, obtain the distance information of the area to be measured.
[0073] Understandably, the second binarized image obtained after morphological processing has a clearer and more accurate outline of the region to be measured, and the distance information obtained by measuring the distance in the region to be measured in the second binarized image is more accurate.
[0074] In practice, based on grayscale and contour information, distance information such as the spacing between or within the areas to be measured can be obtained, and corresponding industrial inspection tasks can be performed based on this distance information.
[0075] The following are two case studies of ranging requirements in industrial inspection.
[0076] like Figure 3 As shown, measuring the distance between two components can determine whether there is an assembly misalignment in the workpiece.
[0077] By detecting the height / width lateral distance of a specific area, it is possible to determine whether a structural component is deformed. Figure 4 As shown, to determine if a certain structural component is an NG (Not Good) product, such as... Figure 5 As shown, a certain structural component is determined to be an OK product.
[0078] According to the ranging method provided in the embodiments of this application, the image of the region to be measured is binarized using the grayscale information and contour information of the region to be measured, and morphological operations are performed on the binarized image to obtain the distance information of the region to be measured. The distance is then measured by machine vision, which effectively improves the accuracy and efficiency of distance measurement.
[0079] In some embodiments, step 120, obtaining a first binarized image corresponding to the first region image based on the grayscale information and contour information of the first region image, may include:
[0080] Based on the grayscale and contour information of the first region image, if it is determined that the grayscale uniformity of the region to be measured is greater than the uniformity threshold and the contour complexity of the region to be measured is less than the complexity threshold, the first region image is binarized to obtain the first binarized image.
[0081] Based on the grayscale information of the first region image, the grayscale uniformity of the region to be measured is determined. Grayscale uniformity is used to characterize whether the pixel value distribution within the region to be measured is uniform.
[0082] In practice, the grayscale uniformity of the area to be measured can be parameters such as the variance or standard deviation of the pixel grayscale values in the area to be measured.
[0083] Based on the contour information of the first region image, the contour complexity of the region to be measured is determined. The contour complexity is used to characterize the complexity of the contour of the region to be measured.
[0084] In practice, the contour complexity of the region to be measured can include information such as the number of contours extracted from the region and the direction of the contours.
[0085] Uniformity threshold and complexity threshold are preset critical values that can be set according to different distance measurement requirements, different workpieces to be measured, or different distance measurement areas.
[0086] In this embodiment, based on the grayscale information and contour information of the first region image, it is determined that the grayscale uniformity of the region to be measured is greater than the uniformity threshold and the contour complexity of the region to be measured is less than the complexity threshold, indicating that the region to be measured is a region with uniform grayscale and a simple contour. The first region image can be directly binarized to obtain the first binarized image.
[0087] In some embodiments, step 120, obtaining a first binarized image corresponding to the first region image based on the grayscale information and contour information of the first region image, may include:
[0088] Based on the grayscale and contour information of the first region image, and if it is determined that the grayscale uniformity of the region to be measured is not greater than the uniformity threshold and the contour complexity of the region to be measured is not less than the complexity threshold, a convolution operation is performed on the first region image to obtain the first real type gradient image.
[0089] The first real-type gradient image is converted to a different image data format to obtain the first byte-type gradient image.
[0090] The first byte type gradient image is binarized to obtain the first binarized image.
[0091] In this embodiment, based on the grayscale information and contour information of the first region image, it is determined that the grayscale uniformity of the region to be measured is not greater than the uniformity threshold and the contour complexity of the region to be measured is not less than the complexity threshold, indicating that the region to be measured is a region with uneven grayscale and complex contour.
[0092] For the range to be measured region with uneven gray levels and complex contours, the first region image can be convolved using the derivative of the Gaussian function to derive the first real type gradient image corresponding to the first region image. The first real type gradient image is a gradient image of real data type.
[0093] It should be noted that the foreground and background grayscale values of the first real type gradient image cannot be distinguished. Therefore, when performing subsequent image operations such as image enhancement and image segmentation, a gradient image of byte data type needs to be used.
[0094] In this embodiment, by converting the image data format of the first real type gradient image to obtain the first byte type gradient image, and then performing binarization processing on the first byte type gradient image, the first binarized image can be obtained.
[0095] In some embodiments, converting the image data format of the first real-type gradient image to obtain a first byte-type gradient image may include:
[0096] The first real-type gradient image is then subjected to absolute value taking and normalization processing in sequence;
[0097] The grayscale range of the first real-type gradient image after absolute value processing and normalization is adjusted to the target grayscale range, and the image data format is converted to obtain the first byte-type gradient image.
[0098] The target grayscale range is the range of pixel values corresponding to the gradient image of the first byte type.
[0099] For example, the target grayscale range can be the range of pixel values from 0 to 255, and the grayscale range of the first real type gradient image can be expanded to 0-255.
[0100] In this embodiment, the absolute value of the first real type gradient image is first taken, and then normalized to adjust the grayscale range of the first real type gradient image to the target grayscale range, which can increase the contrast of the byte type gradient image. After image data format conversion, the first byte type gradient image is obtained.
[0101] In some embodiments, step 130, performing morphological processing on the first binarized image to obtain a second binarized image, includes:
[0102] A morphological opening operation is performed on the first binarized image along the first direction, and a morphological closing operation is performed on the first binarized image along the direction perpendicular to the first direction to extract the region to be measured and obtain the second binarized image.
[0103] The first direction is the direction perpendicular to the distance measurement direction of the area to be measured.
[0104] It is understandable that the morphological opening operation can be an operation of erosion followed by dilation, which can remove small objects, while the morphological closing operation can be an operation of dilation followed by erosion, which can fill small objects.
[0105] In this embodiment, morphological processing is performed on the first binarized image. A morphological opening operation is performed in the direction perpendicular to the distance measurement direction of the region to be measured, and a morphological closing operation is performed in the distance measurement direction of the region to be measured. The shape of the region to be measured in the first binarized image is extracted, thereby improving the accuracy of distance measurement using the second binarized image.
[0106] In some embodiments, step 140, obtaining distance information of the region to be measured based on the second binarized image, includes:
[0107] Blob analysis and circumscribed oblique rectangle calculation are performed on the region to be measured in the second binarized image to obtain the distance information of the region to be measured.
[0108] Blob analysis analyzes the connected components of the same pixels in an image. These connected components are called blobs, and color spots in the image after binarization can be considered as blobs.
[0109] Blob analysis can separate targets from the background and calculate the number, location, shape, orientation, and size of targets, as well as provide the topological structure between related blobs.
[0110] In this embodiment, a Blob analysis is performed on the region to be measured in the second binarized image to separate the region to be measured. The circumscribed oblique rectangle of the region to be measured is calculated, and the distance information of the region to be measured is determined based on the minimum circumscribed oblique rectangle of the region to be measured.
[0111] Taking a first distance measurement region with uniform grayscale and simple outline, and a second distance measurement region with uneven grayscale and complex outline as examples, a specific implementation method is introduced.
[0112] Obtain the first region image of the area to be measured.
[0113] For the first region to be measured, the following can be obtained: Figure 6 The first region image shown can be used to obtain, for the second region to be measured, the following: Figure 10 The first region image shown.
[0114] like Figure 2 As shown, step 1: Gaussian smoothing is performed on the first region image of the area to be measured to blur the image and remove noise.
[0115] for Figure 6 The first region image of the first region to be measured, as shown, can be obtained through smoothing. Figure 7 The first region image shown, for Figure 10 The first region image of the second region to be measured, as shown, can be obtained by smoothing. Figure 11 The first region image shown.
[0116] Step 2: For Figure 7 The grayscale image shown can be directly binarized to obtain... Figure 8 The first binarized image corresponding to the first distance measurement region shown.
[0117] right Figure 11 For the grayscale image shown, perform steps 2.1 to 2.4:
[0118] Step 2.1: [The following text appears to be a separate, unrelated section:] ... Figure 11 The image shown is convolved with the derivative of the following Gaussian function to derive a real-valued image, which is the first real-type gradient image corresponding to the second region to be measured.
[0119]
[0120] Where x and y are Figure 11 The coordinate values of the image shown.
[0121] Step 2.2: Take the absolute value of the first real-type gradient image, change negative values to positive values, and leave positive values unchanged.
[0122] Step 2.3: Obtain the gray-level extreme values of the absolute gradient image of the first real type gradient image, then convert the gray levels used to values greater than or equal to 0 by using the minimum gray value, and then expand all gray levels to the range of 0-255 according to the normalized gray-level amplification factor.
[0123] Step 2.4: Convert the image data format to obtain, for example... Figure 12 The first byte type gradient image is shown.
[0124] Step 2.5: Binarize the first byte-type gradient image that can be processed to obtain the image obtained based on the contour gradient method, such as... Figure 13 The second binarized image is shown.
[0125] Step 3: For example Figure 8 The first binarized image corresponding to the first distance measurement region shown and as follows Figure 13 The second binarized image corresponding to the second distance measurement region shown is subjected to morphological processing. A morphological opening operation is performed in the direction perpendicular to the distance measurement direction, and a morphological closing operation is performed in the distance measurement direction to ensure minimal interference and complete connectivity within the blob region, resulting in the following images: Figure 9 The second binarized image corresponding to the first distance measurement region shown and as follows Figure 14 The second binarized image corresponding to the second distance measurement region is shown.
[0126] Step 4: For example Figure 9The second binarized image corresponding to the first distance measurement region shown and as follows Figure 14 The second binarized image corresponding to the second distance measurement area shown is subjected to Blob analysis and circumscribed oblique rectangle calculation to obtain the width and height dimensions in the distance measurement direction. Then, the width and height dimensions are combined with the indicators to determine whether they meet the deviation requirements, thereby completing the determination of OK and NG products.
[0127] The ranging method provided in this application can be executed by a ranging device. This application uses a ranging device executing the ranging method as an example to illustrate the ranging device provided in this application.
[0128] This application also provides a ranging device.
[0129] like Figure 15 As shown, the ranging device includes:
[0130] The acquisition module 1510 is used to acquire a first region image of the area to be measured.
[0131] The first processing module 1520 is used to obtain a first binarized image corresponding to the first region image based on the grayscale information and contour information of the first region image.
[0132] The second processing module 1530 is used to perform morphological processing on the first binarized image to obtain a second binarized image;
[0133] The third processing module 1540 is used to obtain distance information of the area to be measured based on the second binarized image.
[0134] According to the ranging device provided in the embodiments of this application, the grayscale information and contour information of the region to be measured are used to perform binarization processing on the image of the region to be measured, and morphological operations are performed on the binarized image to obtain the distance information of the region to be measured. The distance is measured by machine vision, which effectively improves the accuracy and efficiency of distance measurement.
[0135] In some embodiments, the first processing module 1520 is configured to perform binarization processing on the first region image to obtain a first binarized image when, based on the grayscale information and contour information of the first region image, it is determined that the grayscale uniformity of the region to be measured is greater than a uniformity threshold and the contour complexity of the region to be measured is less than a complexity threshold.
[0136] In some embodiments, the first processing module 1520 is configured to perform convolution operation on the first region image to obtain a first real type gradient image when, based on the grayscale information and contour information of the first region image, it is determined that the grayscale uniformity of the region to be measured is not greater than a uniformity threshold and the contour complexity of the region to be measured is not less than a complexity threshold.
[0137] The first real-type gradient image is converted to a different image data format to obtain the first byte-type gradient image.
[0138] The first byte type gradient image is binarized to obtain the first binarized image.
[0139] In some embodiments, the first processing module 1520 is used to sequentially perform absolute value processing and normalization processing on the first real type gradient image;
[0140] The grayscale range of the first real-type gradient image after absolute value processing and normalization is adjusted to the target grayscale range, and the image data format is converted to obtain the first byte-type gradient image.
[0141] The target grayscale range is the range of pixel values corresponding to the gradient image of the first byte type.
[0142] In some embodiments, the second processing module 1530 performs a morphological opening operation on the first binarized image along the first direction, performs a morphological closing operation on the first binarized image along the direction perpendicular to the first direction, extracts the region to be measured, and obtains a second binarized image.
[0143] The first direction is the direction perpendicular to the distance measurement direction of the area to be measured.
[0144] In some embodiments, the third processing module 1540 is used to perform Blob analysis and circumscribed oblique rectangle calculation on the distance to be measured region in the second binarized image to obtain distance information of the distance to be measured region.
[0145] The ranging device in this application embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television set (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the scope of the device.
[0146] The ranging device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit it.
[0147] The ranging device provided in this application embodiment can achieve... Figures 1 to 14 The various processes implemented in the method implementation examples will not be described again here to avoid repetition.
[0148] In some embodiments, such as Figure 16 As shown, this application embodiment also provides an electronic device 1600, including a processor 1601, a memory 1602, and a computer program stored in the memory 1602 and executable on the processor 1601. When the program is executed by the processor 1601, it implements the various processes of the above-described ranging method embodiment and achieves the same technical effect. To avoid repetition, it will not be described again here.
[0149] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.
[0150] This application also provides a non-transitory computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the various processes of the above-described ranging method embodiments and achieves the same technical effect. To avoid repetition, it will not be described again here.
[0151] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0152] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described ranging method.
[0153] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0154] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described ranging method embodiments and achieve the same technical effect. To avoid repetition, it will not be described again here.
[0155] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0156] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0157] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0158] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
[0159] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0160] Although embodiments of this application have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of this application, the scope of which is defined by the claims and their equivalents.
Claims
1. A distance measurement method, characterized in that, include: Obtain the first region image of the area to be measured; Based on the grayscale information and contour information of the first region image, if it is determined that the grayscale uniformity of the region to be measured is greater than the uniformity threshold and the contour complexity of the region to be measured is less than the complexity threshold, the first region image is binarized to obtain a first binarized image. Based on the grayscale information and contour information of the first region image, if it is determined that the grayscale uniformity of the region to be measured is not greater than the uniformity threshold and the contour complexity of the region to be measured is not less than the complexity threshold, a convolution operation is performed on the first region image to obtain a first real type gradient image. The first real-type gradient image is converted into an image data format to obtain a first byte-type gradient image; The first byte-type gradient image is binarized to obtain the first binarized image; The first binarized image is subjected to morphological processing to obtain the second binarized image; Based on the second binarized image, the distance information of the region to be measured is obtained.
2. The ranging method according to claim 1, characterized in that, The step of converting the image data format of the first real-type gradient image to obtain a first byte-type gradient image includes: The first real-type gradient image is then subjected to absolute value taking and normalization processing in sequence; The grayscale range of the first real type gradient image after absolute value processing and normalization is adjusted to the target grayscale range, and the image data format is converted to obtain the first byte type gradient image. The target grayscale range is the range of pixel values corresponding to the first byte-type gradient image.
3. The ranging method according to any one of claims 1-2, characterized in that, The step of performing morphological processing on the first binarized image to obtain a second binarized image includes: A morphological opening operation is performed on the first binarized image along the first direction, and a morphological closing operation is performed on the first binarized image along the direction perpendicular to the first direction to extract the region to be measured, thereby obtaining the second binarized image. Wherein, the first direction is the direction perpendicular to the distance measurement direction of the area to be measured.
4. The ranging method according to any one of claims 1-2, characterized in that, The step of obtaining distance information of the region to be measured based on the second binarized image includes: Blob analysis and circumscribed oblique rectangle calculation are performed on the region to be measured in the second binarized image to obtain the distance information of the region to be measured.
5. A ranging device, characterized in that, include: The acquisition module is used to acquire the first region image of the area to be measured. The first processing module is used to obtain a first binarized image corresponding to the first region image based on the grayscale information and contour information of the first region image. The step of obtaining the first binarized image corresponding to the first region image based on the grayscale information and contour information of the first region image includes: Based on the grayscale information and contour information of the first region image, if it is determined that the grayscale uniformity of the region to be measured is greater than the uniformity threshold and the contour complexity of the region to be measured is less than the complexity threshold, the first region image is binarized to obtain the first binarized image. Based on the grayscale information and contour information of the first region image, if it is determined that the grayscale uniformity of the region to be measured is not greater than the uniformity threshold and the contour complexity of the region to be measured is not less than the complexity threshold, a convolution operation is performed on the first region image to obtain a first real type gradient image. The first real-type gradient image is converted into an image data format to obtain a first byte-type gradient image; The first byte-type gradient image is binarized to obtain the first binarized image; The second processing module is used to perform morphological processing on the first binarized image to obtain a second binarized image; The third processing module is used to obtain the distance information of the region to be measured based on the second binarized image.
6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the ranging method as described in any one of claims 1-4.
7. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the ranging method as described in any one of claims 1-4.
8. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the ranging method as described in any one of claims 1-4.
Citation Information
Patent Citations
Lead width and lead space detection method and device for lead in PCB image
CN106228543A