Rotating speed detection method and device based on OpenCV

The center of mass coordinates of the turntable marking points are detected through OpenCV image processing technology, which solves the problems of speed detection accuracy and environmental dependence of traditional methods in narrow spaces, and achieves high-precision speed detection.

CN119438621APending Publication Date: 2025-02-14NANCHANG UNIV
View PDF 12 Cites 0 Cited by

Patent Information

Application Number
CN202510032564.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-09
Publication Date
2025-02-14

AI Technical Summary

Technical Problem

Traditional speed detection methods have problems of environmental dependence and accuracy interference in the measurement of tiny objects in narrow spaces.

Method used

Using OpenCV-based image processing methods, the center of mass coordinates is calculated by detecting the marking points on the turntable, thereby realizing the detection of rotation speed.

Benefits of technology

In a small space, it can detect the rotation speed of the turntable with high accuracy, reduce the impact of environmental noise, and is suitable for the detection of tiny objects under complex working conditions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119438621A_ABST
    Figure CN119438621A_ABST
Patent Text Reader

Abstract

The invention provides a rotating speed detection method and device based on OpenCV, and the method specifically comprises the steps: collecting original rotating disc video data, carrying out the preprocessing of the original rotating disc video data, and converting the original rotating disc video data into an HSV color space; marks with different colors are screened out by adjusting the hue and the brightness; carrying out Canny edge detection on the mark images with different colors to obtain contour video data of the mark; the mass centers of the different marks are calculated according to the contour video data, the rotating speed of the rotating disc is calculated according to changes of the mass center points, the rotating speed detection accuracy and efficiency can be improved, and the method has wide application prospects.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of rotation speed detection, and in particular relates to a rotation speed detection method and device based on OpenCV. Background Art

[0002] In current industrial manufacturing, speed detection of tiny objects under complex working conditions is a basic and important task. Current measurement methods mainly include: speed measurement by tachometer generator, photoelectric digital speed measurement, magnetoelectric speed sensor, magnetic flux leakage speed measurement, vibration speed measurement, etc.

[0003] However, traditional methods such as photoelectric measurement require a relatively wide space, unobstructed laser and measured object, and additional reflective strips must be set up. This measurement method has very stringent requirements on the environment. For the speed measurement requirements of small objects in some narrow spaces, the size of the measuring equipment often limits the measurement. For light pollution or obstruction of the line of sight, the measurement accuracy is often disturbed by environmental noise. Summary of the invention

[0004] In order to overcome the shortcomings of the prior art, the present invention provides a rotation speed detection device and method based on OpenCV, which adopts an image processing means to detect the surface features of the object to be measured and obtain the rotation speed through the changes of two detection marks.

[0005] In order to achieve the above object, the present invention provides a rotation speed detection method based on OpenCV, comprising the following steps: S1, before detection, first mark the turntable, define the mark of the center of the disk as p1, and define the mark of the circumference as p2; S2, when the turntable rotates, the camera device collects video signals from the turntable; S3, creates a hue in OpenCV, sets the adjustment window of saturation and brightness, and selects the video signals storing the motion trajectories of p1 and p2 respectively by adjusting the hue, saturation and brightness; S4, performing binarization processing on the video signals storing the motion trajectories of p1 and p2 respectively to obtain binarized video signals; S5, processing the binary video signal by Gaussian blur algorithm to reduce noise; performing Canny edge detection calculation on the video signal after Gaussian blur to obtain a video signal storing the motion trajectory of the contours of p1 and p2; S6, traverse the pixel points and store the contour coordinates of the detected mark in the contour array; S7, calculating the centroid of the contour array to obtain detection marker points, and obtaining the centroid coordinates of the marker points; S8, calculating the rotation speed of the turntable according to the coordinates of the two detection mark points in the base coordinate system.

[0006] Furthermore, in step S1, the mark is attached to the surface of the turntable in different colors in the form of dot marking.

[0007] Furthermore, in step S2, when the turntable rotates, the coordinates under the viewing angle of the camera device are defined as a base coordinate system, the x-axis is defined as a base coordinate x-axis, and the y-axis is defined as a base coordinate y-axis.

[0008] Furthermore, in step S3, the hue threshold is set to have a minimum of 0 and a maximum of 179, and the saturation and brightness thresholds are set to have a minimum of 0 and a maximum of 255.

[0009] Furthermore, in step S7, the formula for calculating the centroid is: for area A, ; For the centroid coordinate, ; For the centroid coordinate, , in , are the contour coordinates of the detected mark.

[0010] Furthermore, in step S8, the formula for calculating the rotation speed of the turntable is: ; in is the inverse of the video signal frame rate, is the x-coordinate of p1, is the y coordinate of p1, is the x-coordinate of p2, is the y coordinate of p2, for The x coordinate of p1 in the next frame, for The y coordinate of p1 in the next frame, for The x coordinate of p2 in the next frame, for The y coordinate of p2 in the next frame.

[0011] Furthermore, in step S8, it also includes creating a buffer, storing the rpm corresponding to each frame in the buffer, and taking the average value of the data of 10 frames to obtain the final rotation speed value.

[0012] The present invention also provides a rotation speed detection device based on OpenCV, which includes a rotating turntable, detection marks distributed at the center and circumference of the turntable, and distinguished by different colors; a camera device is used to detect the marks, wherein the camera device is facing the rotating turntable to collect video signals; a data processing device obtains the center of mass of different marks by image processing means, and calculates the rotation speed of the turntable according to the change of the center of mass point.

[0013] Furthermore, the camera device is installed above the disc, and the shooting direction is facing the rotating turntable.

[0014] Furthermore, the camera device is a high-definition industrial microscope camera.

[0015] Beneficial effect: The invention discloses a rotation speed detection method based on OpenCV, which performs detection marking or feature selection on the turntable. When the turntable rotates at a low speed or moves slightly at intervals of only one frame, the rotation speed of the turntable can also be accurately measured. By controlling the camera device, it can also meet the measurement requirements in a small space. The measurement method is less affected by the environment and can meet the requirements of high-precision rotation speed detection under complex working conditions. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings and other implementation methods can be obtained based on these drawings without creative work. In the drawings: Figure 1 It is a flow chart of the rotation speed detection method based on OpenCV of the present invention; DETAILED DESCRIPTION

[0017] The specific implementation of the present invention is further described in detail below in conjunction with the accompanying drawings and examples. The following examples are used to illustrate the present invention, but are not intended to limit the scope of the present invention.

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

[0019] In order to simplify the drawings, only the parts related to the present invention are schematically shown in each figure, and they do not represent the actual structure of the product. In addition, in order to simplify the drawings and facilitate understanding, in some figures, only one of the parts with the same structure or function is schematically drawn or marked. In this article, "one" not only means "only one", but also means "more than one".

[0020] It should be further understood that the term “and / or” used in the specification and appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0021] In the embodiments shown in the drawings, the indications of directions (such as up, down, left, right, front and back) used to explain the structure and movement of the various components of the present invention are not absolute but relative. These descriptions are appropriate when these components are in the positions shown in the drawings. If the descriptions of the positions of these components change, the indications of these directions also change accordingly.

[0022] In addition, in the description of the present application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.

[0023] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the specific implementation of the present invention will be described below with reference to the accompanying drawings.

[0024] See also Figure 1 The speed detection method based on OpenCV of the present invention comprises the following steps: S1, before detection, the turntable is first marked, the detection mark is a dot mark with different colors attached to the surface of the turntable, the mark at the center of the turntable is defined as p1, and the mark on the circumference is defined as p2; S2, when the turntable rotates, the camera device collects video signals from the turntable; the camera device is installed above the disk, and the shooting direction is facing the rotating disk; When the disk rotates, the coordinates under the viewing angle of the camera device are defined as a base coordinate system, the x-axis is defined as a base coordinate x-axis, and the y-axis is defined as a base coordinate y-axis; S3, create hue in OpenCV, set adjustment windows for saturation and brightness, set hue threshold to be from 0 to 179, saturation and brightness threshold to be from 0 to 255, and filter out the video signals storing the motion trajectories of p1 and p2 by adjusting hue, saturation and brightness respectively; S4, performing binarization processing on the video signals storing the motion trajectories of p1 and p2 respectively to obtain binarized video signals; Specifically, we first need to select a suitable global threshold T. A common method is to calculate the histogram of the grayscale values ​​of all pixels in the video signal and determine the threshold based on the distribution of the histogram. For example, if the grayscale values ​​of the target and background of the image are very different, the histogram will show an obvious bimodal distribution. The threshold can be selected at the bottom of the valley between the two peaks, which can better separate the target and the background. In addition, the threshold can also be determined based on experience or multiple tests.

[0025] For each frame of the video signal (where x and y represent the coordinates of the pixel), if the grayscale value of the pixel is , then the grayscale value of the pixel is set to 1 (indicating the target); if >T, its grayscale value is set to 0 (indicating background). In this way, the entire image is converted into a binary image with only two grayscale values, 0 and 1, thereby highlighting the target (such as the motion trajectory of the detection mark) and facilitating subsequent analysis and processing. For example, in an image with a grayscale value range of 0 - 255, if the threshold T=128 is selected, then the pixels with grayscale values ​​greater than or equal to 128 will be regarded as the target part and become 1, while the pixels with grayscale values ​​less than 128 will become 0 and become the background part.

[0026] S5, processing the binary video signal by Gaussian blur algorithm to reduce noise; performing Canny edge detection calculation on the video signal after Gaussian blur to obtain a video signal storing the motion trajectory of the contours of p1 and p2; Gaussian blur is an image filtering method based on Gaussian function. Its core idea is to perform weighted average of the grayscale values ​​of the surrounding pixels for each pixel in the image. The closer the pixel is to the center pixel, the greater the weight, and the farther the pixel is, the smaller the weight. For each frame of the video signal (assuming it is a two-dimensional image), , where x and y represent the coordinates of the pixel point), the calculation formula for Gaussian blur is as follows: , in The image after Gaussian blur is The pixel value at is the radius of the Gaussian kernel (determines the size of the neighborhood involved in the calculation), is the standard deviation of the Gaussian function (controls the discreteness of the weight distribution. The larger it is, the more obvious the blur effect is). W is the normalization coefficient, which is used to ensure that the overall brightness of the image remains unchanged. The calculation formula is: .

[0027] The specific steps of Canny edge detection calculation to obtain the video signal storing the motion trajectory of the p1 and p2 contours are: First, the gradient of the image is calculated, and the Sobel operator is used to calculate the gradient of each frame of the video signal. The Sobel operator includes horizontal and vertical direction Two templates: ; For each pixel in the image , its horizontal gradient and vertical gradient It is calculated by convolution with the corresponding template. Then, the gradient amplitude of the pixel point is and the gradient direction The calculation formula is: ; ; After calculating the gradient, non-maximum suppression is required to obtain a more accurate edge. For each pixel, compare its gradient magnitude with the gradient magnitude of the adjacent pixel in its gradient direction. If the gradient magnitude of the pixel is not a local maximum, set its grayscale value to 0 (suppress the point); otherwise, keep its grayscale value. For example, for a horizontal gradient direction ( =0° or 180°), compare the gradient amplitudes of its left and right adjacent pixels; for pixels with a gradient direction that is vertical ( =90° or 270°), and compare the gradient amplitudes of its upper and lower adjacent pixels. In this way, the edge is refined to a single pixel width.

[0028] Set the high threshold T h and low threshold T l (T h >T l ). Pixels with gradient magnitude greater than the high threshold are determined as strong edge points, and pixels with gradient magnitude less than the low threshold are determined as strong edge points. l The pixel point is determined as a non-edge point and its gray value is set to 0. l and high threshold T hIf the pixels between are connected to strong edge points, they are regarded as edge points, otherwise they are regarded as non-edge points. Finally, the discontinuous edge points are connected into complete edges through the edge connection algorithm. For example, when encountering a strong edge point, track along its gradient direction and connect the adjacent edge points until a boundary or non-edge point is encountered. In this way, for the detection marks p1 and p2, after the above series of operations, their contour motion trajectories are reflected in the video signal, thereby obtaining a video signal storing the contour motion trajectories of p1 and p2. Subsequently, the center of mass and other parameters can be further calculated based on these trajectory information to realize speed detection. In practical applications, it is necessary to reasonably select the values ​​of the high threshold and the low threshold according to the characteristics of the video signal and the detection requirements to balance the accuracy and completeness of edge detection.

[0029] S6, traverse the pixel points and store the contour coordinates of the detected mark in the contour array; Traversing the pixels and storing the contour coordinates of the detection mark in the contour array is a key step to accurately extract the contour information of the detection mark after a series of image processing operations (such as binarization, edge detection, etc.), as follows: First, determine the image traversal direction, usually starting from the upper left corner of the image, and traversing each pixel in the image from left to right and from top to bottom. This ensures that the entire image is scanned comprehensively and orderly without missing any pixels. For example, for an image of size M×N (M rows, N columns), start with the pixels in row 0 and column 0, and then process the pixels in other columns of row 0 in sequence. When all pixels in row 0 are processed, start processing pixels in row 1, and so on, until the last row (M-1 row) and the last column (N-1 column) of pixels are processed; Detect edge pixels. When traversing each pixel, determine whether the current pixel is an edge pixel based on the previous Canny edge detection results (assuming that after Canny edge detection, the grayscale value of edge pixels is 1 and the grayscale value of non-edge pixels is 0). If the grayscale value of the current pixel is 1, the pixel is considered to be an edge pixel and may belong to the outline of the detection mark; for example, when traversing to the image with coordinates When a pixel is found, its grayscale value is checked. If the grayscale value is 1, the next step is continued to determine whether the pixel actually belongs to the contour.

[0030] Contour starting point determination: When an edge pixel is found, it is necessary to determine whether it is the starting point of the contour. A simple method is to check whether there is only one edge pixel adjacent to it in its neighborhood pixels (usually considering an 8-neighborhood, that is, the 8 pixels around the current pixel). If so, the pixel may be the starting point of the contour; if there are multiple edge pixels adjacent to it in the neighborhood, it may be other points in the contour (such as the middle point of the contour segment) or noise points (if noise pixels are also displayed as edge pixels after edge detection).

[0031] Once the starting point of the contour is determined, contour tracking begins. Starting from the starting point, the next contour point is found according to certain rules. A common method is to determine the search direction of the next point based on the edge direction. For example, if the edge direction of the current point is roughly horizontal to the right (which can be approximately determined by the previously calculated gradient direction), then in the search for the next pixel point, the neighboring pixels on the right are given priority; if the edge direction is vertically downward, the neighboring pixels below are given priority.

[0032] When searching for the next contour point, it is also necessary to determine whether the pixel found is a true contour point. The determination method is similar to the determination of the contour starting point, that is, to check the number of edge pixels in its neighborhood pixels. If the pixel found meets the conditions of the contour point, its coordinates are recorded and used as the new current point. The next contour point is searched in the edge direction until it returns to the starting point or encounters a situation where it cannot continue tracking (such as encountering an image boundary or failing to find the next contour point that meets the conditions).

[0033] Contour coordinate storage, during the contour tracking process, the coordinates of the found contour points are stored in the contour array in sequence. The contour array can be a two-dimensional array, each row stores the coordinates of a contour point, and when a contour is tracked, the coordinate information of all points of the contour is stored in the contour array. If there are multiple detection marks in the image, there may be multiple contours, and the above contour starting point judgment, contour tracking and coordinate storage process needs to be repeated, and the coordinates of each contour are stored in different arrays or in the same array by specific marks to distinguish different contours.

[0034] S7, calculate the centroid of the contour array to obtain the detection mark point, and obtain the centroid coordinates of the mark point; specifically, when the turntable rotates, the contour coordinate array of the detection mark point is obtained by the image processing method, and the array is loaded into the Shoelace theorem to obtain the center point of the detection mark: The formula for calculating the centroid is: For area A, ; For the centroid coordinate, ; For the centroid coordinate, , in , are the contour coordinates of the detected mark.

[0035] S8, calculating the rotation speed of the turntable according to the coordinates of the two detection mark points in the base coordinate system; The specific steps are as follows: after obtaining two marking points, the rotation speed of the turntable is calculated by the coordinates of the two detection marking points in the base coordinate system. The calculation formula of the rotation speed can be expressed as: ; in is the inverse of the video signal frame rate, is the x-coordinate of p1, is the y coordinate of p1, is the x-coordinate of p2, is the y coordinate of p2, for The x coordinate of p1 in the next frame, for The y coordinate of p1 in the next frame, for The x coordinate of p2 in the next frame, for The y coordinate of p2 in the next frame.

[0036] In order to make the result more accurate, as a preferred embodiment, in step S8, a buffer is further created, in which the rpm corresponding to each frame is stored, and the data of 10 frames are averaged to obtain the final rotation speed value.

[0037] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0038] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0039] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0040] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0041] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the relevant field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents. Any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.

Claims

1. A speed detection method based on OpenCV, characterized in that: The steps include: S1, before detection, first mark the turntable, define the mark of the center of the disk as p1, and define the mark of the circumference as p2; S2, when the turntable rotates, the camera device collects video signals from the turntable; S3, creates a hue in OpenCV, sets the adjustment window of saturation and brightness, and selects the video signals storing the motion trajectories of p1 and p2 respectively by adjusting the hue, saturation and brightness; S4, performing binarization processing on the video signals storing the motion trajectories of p1 and p2 respectively to obtain binarized video signals; S5, processing the binary video signal by Gaussian blur algorithm to reduce noise; performing Canny edge detection calculation on the video signal after Gaussian blur to obtain a video signal storing the motion trajectory of the contours of p1 and p2; S6, traverse the pixel points and store the contour coordinates of the detected mark in the contour array; S7, calculating the centroid of the contour array to obtain detection marker points, and obtaining the centroid coordinates of the marker points; S8, calculating the rotation speed of the turntable according to the coordinates of the two detection mark points in the base coordinate system.

2. The detection method according to claim 1, characterized in that: In step S1, the marks are attached to the surface of the turntable in different colors in the form of dot markings.

3. The detection method according to claim 1, characterized in that: In step S2, when the turntable rotates, the coordinates under the viewing angle of the camera device are defined as a base coordinate system, the x-axis is defined as a base coordinate x-axis, and the y-axis is defined as a base coordinate y-axis.

4. The detection method according to claim 1, characterized in that: In step S3, the hue threshold is set to have a minimum of 0 and a maximum of 179, and the saturation and brightness thresholds are set to have a minimum of 0 and a maximum of 255.

5. The detection method according to claim 1, characterized in that: In step S7, the formula for calculating the centroid is: for area A, ; For the centroid coordinate, ; For the centroid coordinate, , in , are the contour coordinates of the detected mark.

6. The detection method according to claim 1, characterized in that: In step S8, the formula for calculating the rotation speed of the turntable is: ; in is the inverse of the video signal frame rate, is the x-coordinate of p1, is the y coordinate of p1, is the x-coordinate of p2, is the y coordinate of p2, for The x coordinate of p1 in the next frame, for The y coordinate of p1 in the next frame, for The x coordinate of p2 in the next frame, for The y coordinate of p2 in the next frame.

7. The detection method according to claim 1, characterized in that: In step S8, it also includes creating a buffer, storing the rpm corresponding to each frame in the buffer, and taking the average value of the data of 10 frames to obtain the final rotation speed value.

8. A rotation speed detection device based on OpenCV, characterized in that: The detection device includes a rotating turntable, and detection marks are distributed at the center and circumference of the turntable and are distinguished by different colors; a camera device is used to detect the marks, wherein the camera device is facing the rotating turntable to collect video signals; The data processing device obtains the centroids of different marks by image processing means, and calculates the rotation speed of the turntable according to the change of the centroid point.

9. The speed detection device based on OpenCV according to claim 8, characterized in that: The camera device is arranged above the disc, and the shooting direction faces the rotating turntable.

10. The speed detection device based on OpenCV according to claim 8, characterized in that: The camera device is a high-definition industrial microscope camera.

Citation Information

Patent Citations

  • Rotational speed detection method and device

    CN109001484A

  • Spine coronal plane balance parameter automatic measurement method based on computer vision

    CN111951216A

  • Space-time image velocity measurement method and device based on adaptive edge detection

    CN116342656A

  • Industrial glass defect detection method based on OpenCV optimization algorithm

    CN118172322A

  • Non-contact type rotary speed measuring system

    CN201489014U