Fitting method based on random generation screening and application thereof
1. A fitting method based on random generation screening is characterized by comprising the following steps:
s1, carrying out image shooting operation on the piece to be measured through a camera;
s2, selecting the region needing fitting, and marking a plurality of pixel points of the region as P1-Pn;
S3, selecting P first1-PnRandomly selecting two pixel points and fitting to determine a straight line L1Separately calculating and removing the determined straight line L1A distance straight line L between the pixel points other than the two pixel points1Then all pixel points are separated from the straight line L1The total length of the line segment is X by adding the distance of the first and second lines1;
S4, repeating the operation of S3, randomly screening other two pixel points and determining another straight line L2Separately calculating and removing the determined straight line L2A distance straight line L between the pixel points other than the two pixel points2Then all pixel points are separated from the straight line L2Of (2) isThe total length of the line segment obtained by adding the distances is X2Until all pixel points are fitted, and the distance straight line L of all pixel points is calculatedmThe total length of the line segment is X by adding the distance of the first and second linesm;
Wherein m is n (n-1)/2, and n is the number of all pixel points;
s5, then, X is divided according to length1~XmSelecting and sorting from small to large, and selecting X1~XmThe middle length is sorted to the front section Z;
s6, deducing all pixel points P forming the total length X of the line segment in the selected interval Z;
and S7, performing linear fitting on all the pixel points P determined in the S5 to re-fit the pixel points P into a straight line, namely the target fitting straight line L.
2. The fitting method based on the random generated filtering of claim 1, wherein the length range of the Z interval in S5 is the first 50%.
3. The fitting method based on random generated filtering of claim 1, wherein the point selection positions of each time two selected pixel points P in S4 are fitted are different.
4. The fitting method based on random generation screening of claim 1, wherein when the pixel points are arranged in a three-dimensional space structure, a curve L to be fitted is formed by the pixel pointsmIs a three-dimensional curve, i.e. a three-dimensional arc or a three-dimensional circular curve, and the spacing distance is a three-dimensional spatial spacing distance.
5. The fitting method based on the random generation screening of claim 1, wherein when the pixel points are in a two-dimensional space, a fitted linear equation of the pixel points is a linear straight line or a two-dimensional curve, and the distance is a two-dimensional space distance.
6. The fitting method based on random generation screening of claim 1, wherein the pixels are labeled as sub-pixels, i.e. a plurality of individual independent pixels are synthesized.
7. The fitting method based on random generation screening of claim 6, wherein the pixel point mark adopts the brightness and darkness of the photosensitive intensity of the pixel point surface to determine the pixel point position.
8. The fitting method based on the random generated filtering as claimed in any one of claims 1 to 7, wherein the fitting method based on the random generated filtering is applied to the edge linear fitting of the image picture.
Background
Along with the popularization rate of smart phones is higher and higher in recent years, particularly, the performance of chips adopted by smart phones is gradually improved, and the computing power of the chips is unprecedentedly developed, so that numerous APPs are derived, more changes are brought to the functions of the smart phones, and more interactive experiences are enriched.
The image is formed by combining a plurality of pixel points, the pixel points are basic composition units of the image, and the higher the DPI value of the pixel points is, the higher the image quality of the image is. While the industrial production and processing are gradually refined and standardized, the higher the precision requirement on the parts is, the more the traditional manual measurement mode can not meet the precision measurement requirement of the parts, and thus the image photographing measurement method is produced.
In the actual use process, the image photographing measurement method photographs the to-be-measured piece and then performs linear fitting to generate a real image size and feed the real image size back to a photographer, so that the image photographing measurement method is more intuitive. However, in the image shooting process, a plurality of interference pixel points exist, the number of the interference pixel points is not large, and when the linear fitting method is directly adopted for fitting, the synthetic deviation which influences the interference pixel points on the fitting straight line exists.
In chinese patent CN111310108A, a linear fitting method and system and a storage medium are disclosed, in which a plurality of vector sets are established by inputting, the square of unsigned uncorrelated coefficients of the vectors is calculated, a threshold is set and data noise (noise) is determined, if the data noise (noise) is large, i.e. it deviates more from the real data, data points corresponding to the square of the uncorrelated coefficients are calculated, which are not the remaining data after each data point is deleted, and then the noise (noise) with large deviation is deleted, and linear fitting is performed again on other noises (noise). However, when such noise is large (degree of noise deviation), data noise (noise) is first determined using a specific equation, but the limit is large. When linear fitting is carried out, pixel points generated by pictures shot in various scenes are all irregular spatial positions or irregular plane structures and are not completely adapted to the specific equation, so that the judgment of noise points is wrong, and the fitting accuracy of a fitting straight line is influenced.
Disclosure of Invention
Aiming at the defects of the prior art, the invention aims to provide a fitting method based on random generation screening and application thereof, and solves the technical problems in the prior art.
The purpose of the invention can be realized by the following technical scheme:
a fitting method based on random generation screening comprises the following steps:
s1, carrying out image shooting operation on the piece to be measured through a camera;
s2, selecting the region needing fitting, and marking a plurality of pixel points of the region as P1-Pn;
S3, selecting P first1-PnRandomly selecting two pixel points and determining a straight line L1Separately calculating and removing the determined straight line L1A distance straight line L between the pixel points other than the two pixel points1Then all pixel points are separated from the straight line L1The total length of the line segment is X by adding the distance of the first and second lines1;
S4, repeating the operation of S3, randomly screening other two pixel points and determining another straight line L2Separately calculating and removing the determined straight line L2A distance straight line L between the pixel points other than the two pixel points2Then all pixel points are separated from the straight line L2The total length of the line segment is X by adding the distance of the first and second lines2Until all pixel points are fitted, and the distance straight line L of all pixel points is calculatedmThe total length of the line segment is X by adding the distance of the first and second linesm;
Wherein m is n (n-1)/2, and n is the number of all pixel points;
s5, then, X is divided according to length1~XmSelecting and sorting from small to large, and selecting X1~XmThe middle length is sorted to the front section Z;
s6, deducing all pixel points P forming the total length X of the line segment in the selected interval Z;
and S7, performing linear fitting on all the pixel points P determined in the S5 to re-fit the pixel points P into a straight line, namely the target fitting straight line L.
Further, the length range of the zone Z in S5 is the first 50%.
Further, the point selection positions of the two pixel points P selected in S4 at each time are different from each other when fitting.
Furthermore, when the pixel points are arranged in the three-dimensional space structure, the curve L which is fit to be synthesized by the pixel points is formedmIs a three-dimensional curve, i.e. a three-dimensional arc or a three-dimensional circular curve, and the spacing distance is a three-dimensional spatial spacing distance.
Furthermore, when the pixel points are in a two-dimensional space, the fitted linear equation of the pixel points is a linear straight line or a two-dimensional curve, and the distance between the pixel points is the distance between the two-dimensional space and the linear straight line.
Further, the pixel points are marked as sub-pixel points, namely, a plurality of independent pixel points are synthesized.
Further, the pixel point mark adopts the light and shade of the photosensitive intensity of the pixel point surface to determine the position of the pixel point.
Further, the fitting method of random generation screening is applied to edge linear fitting of the image picture.
The invention has the beneficial effects that:
1. according to the linear fitting method adopted by the invention, firstly, linear fitting is carried out on any two pixel points, so that the distance between other discrete points and the fitted straight line is determined, and then invalid pixel points with high discrete degree are removed.
2. The fitting method adopted by the invention can effectively remove the interfered invalid pixel points and carry out linear fitting on the valid pixel points again so as to improve the fitting precision.
Drawings
In order to more clearly illustrate the embodiments or technical solutions in the prior art of the present invention, the drawings used in the description of the embodiments or prior art will be briefly described below, and it is obvious for those skilled in the art that other drawings can be obtained based on these drawings without creative efforts.
FIG. 1 is a schematic overall flow diagram of an embodiment of the present invention;
FIG. 2 is a schematic illustration of a linear fit L1 straight line for an embodiment of the present invention;
FIG. 3 is a schematic illustration of a linear fit L2 straight line for an embodiment of the present invention;
FIG. 4 is a schematic diagram of a linear fit final state of an embodiment of the present invention;
FIG. 5 is a schematic diagram of a fitted physical simulation according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
As shown in fig. 1, an embodiment of the present invention provides a fitting method based on random generation screening, including the following steps:
and S1, carrying out image shooting operation on the to-be-measured object through the camera so as to clearly show the position of a single pixel point of the shot picture.
S2, selecting the region needing fitting, and marking a plurality of pixel points in the region as P1-Pn(ii) a Meanwhile, the pixel points can be marked as sub-pixel points according to needs, namely a plurality of independent pixel points are combined into a calibration point, then the calibration point is subjected to linear fitting, the linear fitting in the fitting state can be suitable for the linear fitting in the rough state, the calculation is convenient (a plurality of pixel points can be integrated into one for calculation), and the pixel point marking adopts the pixel point surfaceThe light and shade of the light intensity can be used for determining the position of the pixel point, namely a threshold value can be set, when the light intensity is larger than the threshold value, the pixel point is determined to be an effective pixel point, and when the light intensity is smaller than the set threshold value, the ineffective pixel point is removed.
S3, as shown in FIG. 2, P is selected first1-PnRandomly selecting two pixel points and determining a straight line L1Separately calculating and removing the determined straight line L1A distance straight line L between the pixel points other than the two pixel points1Then all pixel points are separated from the straight line L1The total length of the line segment is X by adding the distance of the first and second lines1。
S4, as shown in FIG. 3, repeating S3, randomly screening two other pixel points and determining another straight line L2(the selected point positions of two selected pixel points P are different when the two selected pixel points P are matched each time, so that the pixel points can be linearly matched each time, the accuracy of generating a straight line is improved), and the straight line L is determined by calculation and removal respectively2A distance straight line L between the pixel points other than the two pixel points2Then all pixel points are separated from the straight line L2The total length of the line segment is X by adding the distance of the first and second lines2By adopting the method, another two pixel points are randomly screened every time until all the pixel points are completely fitted, and the distance straight line L between all the pixel points is calculatedmThe total length of the line segment is X by adding the distance of the first and second linesm;
Wherein m is n (n-1)/2, and n is the number of all pixel points;
meanwhile, m is the number of times of linear fitting, and the more the number of times of fitting is, the finer the final fitting result is.
S5, as shown in FIG. 4, then X is divided according to the length1~XmSelecting and sorting from small to large, and selecting X1~XmThe middle length is sorted to the front section Z; according to the requirement, the length range of the interval Z can be controlled to be 50 percent, namely when the pixel points are more concentrated on the periphery of the straight line formed by fitting, the total length X of the line segment is obtainedmThe smaller the pixel point is, the more the pixel point is dispersed around the fitted and formed straight line, the total length of the line segment is obtainedDegree XmThe larger the pixel point is, the more dispersed pixel points are invalid pixel points and are not in the fitting range, (meanwhile, the length range of the interval Z can be controlled and adjusted according to the precision requirement, when the control is less than 50%, all the pixel points of the fitted straight line are more concentrated on the periphery of the fitted straight line, the precision is higher, when the control is more than 50%, all the pixel points of the fitted straight line are more dispersed on the periphery of the fitted straight line, the precision is reduced, and the control and adjustment can be carried out according to the actual fitting requirement).
S6, deducing all the pixels P forming the total length X of the line segment in the selected interval Z, i.e. the pixels of all the fitted lines within the first 50% of the interval range are determined again.
And S7, performing linear fitting on all the pixel points P determined in the S5 to re-fit the pixel points P into a straight line, namely the target fitting straight line L.
As shown in fig. 5, when the pixel point marks are arranged in the three-dimensional space structure, the straight line L to be synthesized is formedmThe space distance is a three-dimensional space distance, and the space distance is a three-dimensional curve structure, namely a three-dimensional arc line or a three-dimensional circular curve; and the spacing distance is a three-dimensional spacing distance.
When the pixel points are in the two-dimensional space, the fitted linear equation of the pixel points is a linear straight line or a two-dimensional curve, and the distance is the distance between the two-dimensional space (for more visual expression, the pixel points are expressed in a straight line fitting mode, and the pixel points can also express the same effect in other curve fitting modes).
Further, a fitting method of random generation screening is applied to edge linear fitting of the image picture.
The linear fitting method adopted by the whole method removes non-concentrated ineffective pixel points through a fitting method of randomly generating and screening, ensures that effective pixel points which are re-fitted are in an effective area range (are more refined), approaches formal and effective edge lines, and can greatly improve the accuracy of a fitting line when fitting (according to requirements, under the state of a three-dimensional space, the three-dimensional curve fitting can also be realized by adopting the linear fitting mode of the three-dimensional space).
In the description herein, references to the description of "one embodiment," "an example," "a specific example" or the like are intended to mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the invention. In this specification, the schematic representations of the terms used above do not necessarily refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
The foregoing shows and describes the general principles, essential features, and advantages of the invention. It will be understood by those skilled in the art that the present invention is not limited to the embodiments described above, which are described in the specification and illustrated only to illustrate the principle of the present invention, but that various changes and modifications may be made therein without departing from the spirit and scope of the present invention, which fall within the scope of the invention as claimed.
- 上一篇:石墨接头机器人自动装卡簧、装栓机
- 下一篇:基于图像特征信息的精密工件台倾角检测方法