Machine vision-based cattle body ruler measurement method
阅读说明:本技术 基于机器视觉的牛体尺测量方法 (Machine vision-based cattle body ruler measurement method ) 是由 滕峰 张嘉森 王思嘉 杨晨 于 2019-12-19 设计创作,主要内容包括:本发明实施例公开了一种基于机器视觉的牛体尺测量方法,包括:步骤1:使用固定长度的标签贴于牛体侧身;步骤2:拍摄贴有标签的牛侧身图像,计算标签的像素长度,通过标签真实长度与像素比例,算出图像上单位像素对应的实际距离;步骤3:提取图像中的牛图像以及牛轮廓的数据;步骤4:对牛轮廓数据分析;步骤5:定位牛体的特征点;步骤6:根据特征点计算牛体尺。本发明使用机器视觉的方式,对牛的体尺信息进行测量,极大的减少了人工成本,且该方式属于无接触式,不会对牛造成任何应激反应,并具有较高的准确率;且无设备部署需求,只需利用随身携带的手机与标签纸,即可方便的完成对牛只的体尺测量。(The embodiment of the invention discloses a method for measuring a bovine body ruler based on machine vision, which comprises the following steps: step 1: the label with fixed length is attached to the side of the cow body; step 2: shooting a side body image of a cow with a label, calculating the pixel length of the label, and calculating the actual distance corresponding to a unit pixel on the image according to the ratio of the real length of the label to the pixel; and step 3: extracting data of a cattle image and a cattle outline in the image; and 4, step 4: analyzing the cattle contour data; and 5: positioning feature points of the cattle body; step 6: and calculating the body size of the cattle according to the characteristic points. The invention uses the machine vision mode to measure the body size information of the cattle, thereby greatly reducing the labor cost, and the mode belongs to non-contact type, does not cause any stress reaction to the cattle and has higher accuracy; and the device is not required to be deployed, and the body size of the cow can be conveniently measured only by using a portable mobile phone and label paper.)
1. A method for measuring a body size of a cow based on machine vision is characterized by comprising the following steps:
step 1: the label with fixed length is attached to the side of the cow body;
step 2: shooting a side body image of the cow with the label, matching the label on the cow body by using a matching algorithm, calculating the pixel length of the label, and calculating the actual distance corresponding to a unit pixel on the image according to the real length of the label and the pixel proportion, wherein the proportion is ruler;
and step 3: removing the parts of the image which are irrelevant to the cattle, and extracting the cattle image and the cattle outline data in the image;
and 4, step 4: analyzing the cattle contour data, and calculating to obtain section data and distance data from the cattle back to the cattle belly;
and 5: positioning the characteristic points of the cattle body according to the calculated data;
step 6: and calculating the body size of the cattle according to the characteristic points.
2. The machine vision-based bovine body ruler measuring method of claim 1 wherein said step 3 comprises:
and a substep of extracting the cattle image: extracting the cattle in the image by using a cattle extraction algorithm, and removing parts irrelevant to the cattle;
and a substep of acquiring the profile of the cow: using an edge detection algorithm to obtain a plurality of contour data in an image, sequencing the plurality of contour data from outside to inside, wherein the outmost layer of the contour is the contour data of the cattle to be obtained, and the contour data of the cattle comprises a plurality of coordinates;
and n is the total number of contour points.
3. The machine vision-based bovine body ruler measuring method of claim 2 wherein said step 4 comprises:
normalization profile data substep: scaling the numerical range of the profile data on the x-axis to
Normalization formula:
whereinAs a result of the original value of the value,
calculating section data substep: scanning the contour data of the cattle from the left side to the right side of the x axis, and subtracting the coordinate y value of the lowest edge from the coordinate y value of the uppermost edge to obtain the section data of the contour coordinate of the x axis
Positioning the bun shell: analyzing the normalized profile data of the chignon using a machine learning method
Positioning the cattle nojiri substep: using machine learning method to analyze the obtained cattle nojiri in normalized profile data
Fitting a cattle back equation substep: intercepting
fitting the data by using a least square method to obtain a cattle back fitting linear equation
yback= kx + b, wherein;
Calculating the distance from the cow back to the cow belly sub-step: calculating the average value of the integral section data
4. The machine vision-based bovine body ruler measuring method of claim 3 wherein said step 5 comprises:
chignon positioning substep:
A back positioning sub-step: intercepting
A cattle nojiri localizer step:
Positioning the scapula front end: on the basis of the chignon coordinates, the y value is positively deviated from the length from the cattle back to the cattle belly, namely the coordinates (x) of the front end of the shoulder bladeThe front end of the scapula is provided with a shoulder blade,yanterior end of scapula);
An abdomen positioning sub-step: offset in longitudinal axis coordinate on back
A front hoof positioning sub-step: find the maximum coordinate of the slice in the left chignon part, defined as front hoof (x)The front hoof is a common hoof,yfront hoof)。
5. The machine vision-based bovine body size measuring method according to claim 4, wherein in said step 6,
the length of the body is the distance from the chignon to the cattle nojiri:
the oblique length of the body is the distance from the cattle nojiri to the front end of the scapula:
the abdominal depth is the distance from the back to the abdomen:
the height of the body is the distance from the chignon to the forehoof:
Technical Field
The invention relates to the technical field of body ruler measurement, in particular to a body ruler measurement method based on machine vision.
Background
According to the traditional method for measuring the body size of the cattle, a worker needs to use measuring tools such as a flexible rule and a tape measure to measure multiple indexes such as the body height, the body slant length and the body straight length of the cattle, and the manual measuring mode has certain measuring difficulty, high cost and low speed and can cause stress reaction of the cattle.
Disclosure of Invention
The technical problem to be solved by the embodiment of the invention is to provide a method for measuring the body size of a cow based on machine vision, so that the measurement difficulty is reduced.
In order to solve the technical problem, an embodiment of the present invention provides a method for measuring a bovine body size based on machine vision, including:
step 1: the label with fixed length is attached to the side of the cow body;
step 2: shooting a side body image of the cow with the label, matching the label on the cow body by using a matching algorithm, calculating the pixel length of the label, and calculating the actual distance corresponding to a unit pixel on the image according to the real length of the label and the pixel proportion, wherein the proportion is ruler;
and step 3: removing the parts of the image which are irrelevant to the cattle, and extracting the cattle image and the cattle outline data in the image;
and 4, step 4: analyzing the cattle contour data, and calculating to obtain section data and distance data from the cattle back to the cattle belly;
and 5: positioning the characteristic points of the cattle body according to the calculated data;
step 6: and calculating the body size of the cattle according to the characteristic points.
Further, the step 3 comprises:
and a substep of extracting the cattle image: extracting the cattle in the image by using a cattle extraction algorithm, and removing parts irrelevant to the cattle;
and a substep of acquiring the profile of the cow: using an edge detection algorithm to obtain a plurality of contour data in an image, sequencing the plurality of contour data from outside to inside, wherein the outmost layer of the contour is the contour data of the cattle to be obtained, and the contour data of the cattle comprises a plurality of coordinates;
and n is the total number of contour points.
Further, the step 4 comprises:
normalization profile data substep: scaling the value range of the profile data on the upper x-axis to
In the above-mentioned manner,for hyper-parameters, the normalized profile data is recorded as;Normalization formula:;
wherein
As a result of the original value of the value,for scaled values, R is a set containing several real numbers;calculating section data substep: scanning the contour data of the cattle from the left side to the right side of the x axis, and subtracting the coordinate y value of the lowest edge from the coordinate y value of the uppermost edge to obtain the section data of the contour coordinate of the x axis
;;
;
Positioning the bun shell: analyzing the normalized profile data of the chignon using a machine learning method
The position of the chignon is obtained Chignon nail;Positioning the cattle nojiri substep: using machine learning method to analyze the obtained cattle nojiri in normalized profile data
The x-axis position of the nojiri is obtained Nijiri (a kind of cattle);Fitting a cattle back equation substep: intercepting
Chignon nailAnd nijiri (a kind of cattle)Normalized profile data of (a) betweenAnd only the profile data of the uppermost edge is taken, and the fitting data satisfies the following relation:;
fitting the data by using a least square method to obtain a cattle back fitting linear equation
back;yback= kx + b, wherein,;
Calculating the distance from the cow back to the cow belly sub-step: calculating the average value of the integral section data
The abdomen of the cattle is locatedAndbetween the vertical lines, cutting the section data between the vertical lines, and averaging the section data secCalculating the average value of the section data within the threshold value sigma to obtain the distance from the back of the cow to the belly of the cow abdominal;;
。
Further, the step 5 comprises:
chignon positioning substep: chignon nailEquation of straight line fitting between X-axis line and cattle back
The intersection point is the chignonThe nail obtains the coordinates (x) of the chignonThe head of the user can be chignon,ychignon nail);A back positioning sub-step: intercepting
Chignon nailAnd nijiri (a kind of cattle)Section data betweenFinding the coordinate of the maximum value in the intercepted tangent plane dataWill be maxSubstituted cattle back fitting linear equation backObtaining the back coordinates (x)The back part of the chair is provided with a back part,yback part);A cattle nojiri localizer step: x is the number ofNijiri (a kind of cattle)The intersection point of the x-axis line and the y-axis line is the cattle nojiri to obtain the cattle nojiri coordinate (x)The feed additive of the beef nojiri,ynijiri (a kind of cattle));
Positioning the scapula front end: on the basis of the chignon coordinates, the y value is positively deviated from the length from the cattle back to the cattle belly, namely the coordinates (x) of the front end of the shoulder bladeThe front end of the scapula is provided with a shoulder blade,yanterior end of scapula);
An abdomen positioning sub-step: offset in longitudinal axis coordinate on backGet the abdomen (x)The abdomen part of the patient is provided with a plurality of abdominal muscles,yabdomen part);
A front hoof positioning sub-step: find the maximum coordinate of the slice in the left chignon part, defined as front hoof (x)The front hoof is a common hoof,yfront hoof)。
Further, in the step 6,
the length of the body is the distance from the chignon to the cattle nojiri:
;
the oblique length of the body is the distance from the cattle nojiri to the front end of the scapula:
;
the abdominal depth is the distance from the back to the abdomen:
;
the height of the body is the distance from the chignon to the forehoof:
。
the invention has the beneficial effects that: the invention uses the machine vision mode to measure the body size information of the cattle, thereby greatly reducing the labor cost, and the mode belongs to non-contact type, does not cause any stress reaction to the cattle and has higher accuracy; and the device is not required to be deployed, and the body size of the cow can be conveniently measured only by using a portable mobile phone and label paper.
Drawings
FIG. 1 is a flow chart of a method for measuring a body size of a cow based on machine vision according to an embodiment of the present invention.
Fig. 2 is a schematic diagram of an extracted bovine image according to an embodiment of the present invention.
FIG. 3 is a schematic representation of a bovine profile according to an embodiment of the present invention.
FIG. 4 is a schematic diagram of the measurement of the key points and body size of cattle according to the embodiment of the present invention.
Description of the reference numerals
Chignon 1
Back 2
Nijiri 3
Scapular front end 4
Abdomen 5
And a front hoof 6.
Detailed Description
It should be noted that the embodiments and features of the embodiments in the present application can be combined with each other without conflict, and the present invention is further described in detail with reference to the drawings and specific embodiments.
If directional indications (such as up, down, left, right, front, and rear … …) are provided in the embodiment of the present invention, the directional indications are only used to explain the relative position relationship between the components, the movement, etc. in a specific posture (as shown in the drawing), and if the specific posture is changed, the directional indications are changed accordingly.
In addition, the descriptions related to "first", "second", etc. in the present invention are only used for descriptive purposes and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature.
Referring to fig. 1, the method for measuring a bovine body size based on machine vision according to the embodiment of the present invention includes steps 1 to 6.
Step 1: arranging a reference object, and attaching a label with a fixed length to the side of the cow body. For example, 8cm blue border labels are applied to the sides of the cattle.
Step 2: shooting a side body image of the cow with the label, matching the label on the cow body by using a matching algorithm, calculating the pixel length of the label, and calculating the actual distance corresponding to a unit pixel on the image according to the real length of the label and the pixel proportion, wherein the proportion is ruler.
And step 3: the cattle irrelevant part in the image is removed, and a cattle image (shown in figure 2) and the data of the cattle outline (shown in figure 3) in the image are extracted.
And 4, step 4: and analyzing the cattle contour data, and calculating to obtain section data and distance data from the cattle back to the cattle belly.
And 5: and positioning the characteristic points of the cattle body according to the calculated data. The bovine keypoints were located as shown in figure 4.
Step 6: and calculating the body size of the cattle according to the characteristic points.
As an embodiment, assume that the face of the cow is facing to the left, i.e., the head of the cow is to the left of the tail of the cow. For the case where the face of the cow is facing the right side, the image is flipped over so that the face of the cow is facing the left side. The step 3 comprises the following steps:
and a substep of extracting the cattle image: extracting the cattle in the image by using a cattle extraction algorithm, and removing parts irrelevant to the cattle, as shown in FIG. 2;
and a substep of acquiring the profile of the cow: using an edge detection algorithm to obtain a plurality of contour data in an image, sequencing the plurality of contour data from outside to inside, wherein the outmost layer of the contour is the contour data of the cattle required to be obtained, and the contour data contourr comprises a plurality of coordinates, as shown in fig. 3 and shown in the following formula;
and n is the total number of contour points.
As an embodiment, the step 4 includes:
normalization profile data substep: scaling the numerical range of the profile data on the x-axis to
In the above-mentioned manner,for hyper-parameters, the normalized profile data is recorded as;Normalization formula:
;whereinAs a result of the original value of the value,for scaled values, R is a set containing several real numbers;
calculating section data substep: the contour data of a cow is scanned from the left side to the right side of the x-axis, and the coordinates of the uppermost edge are used as the contour coordinates of the x-axis
Value minus the coordinates of the lowest edgeValue, obtaining section data;;
;
Positioning the bun shell: analyzing the normalized profile data of the chignon using a machine learning method
The position of the chignon is obtained Chignon nail;Positioning the cattle nojiri substep: using machine learning method to analyze the obtained cattle nojiri in normalized profile data
The position of the upper part of the Chinese medicinal herb is obtainedAt the x-axis position Nijiri (a kind of cattle);Fitting a cattle back equation substep: intercepting
Chignon nailAnd nijiri (a kind of cattle)Normalized profile data of (a) betweenAnd only the profile data of the uppermost edge is taken, and the fitting data satisfies the following relation:;
fitting the data by using a least square method to obtain a cattle back fitting linear equation
;Wherein, in the step (A),;
calculating the distance from the cow back to the cow belly sub-step: calculating the average value of the integral section data
The abdomen of the cattle is located Chignon nailAnd nijiri (a kind of cattle)Between the vertical lines, cutting the section data between the vertical lines, and averaging the section dataCalculating the average value of section data within the threshold value sigma to obtain the distance d from the back of the cow to the belly of the cowabdominal;;
。
As an embodiment, the step 5 includes:
chignon 1 positioning substep:
chignon nailEquation of straight line fitting between X-axis line and cattle backThe point of intersection is chignon 1, and obtains the chignon 1 coordinate (x)The head of the user can be chignon,ychignon nail);Back 2 positioning sub-step: intercepting
Chignon nailAnd nijiri (a kind of cattle)Section data betweenFinding the coordinate of the maximum value in the intercepted tangent plane dataWill be maxSubstituted cattle back fitting linear equationObtaining the Back 2 coordinate (x)The back part of the chair is provided with a back part,yback part);Nojiri 3 positioning substep: x is the number ofNijiri (a kind of cattle)The intersection point of the x-axis line and the y-axis line is cattle nojii 3 to obtain the coordinate of cattle nojii 3 (xThe feed additive of the beef nojiri,ynijiri (a kind of cattle));
The shoulder blade front end 4 positioning sub-step: on the basis of the 1 coordinate of the chignon, the y value is positively deviated from the length from the cattle back to the cattle belly, namely the 4 coordinate (x) of the front end of the shoulder bladeThe front end of the scapula is provided with a shoulder blade,yanterior end of scapula);
Abdomen 5 positioning substep: offset by d on the ordinate of the longitudinal axis on the back 2abdominalObtain the abdomen 5 coordinate (x)The abdomen part of the patient is provided with a plurality of abdominal muscles,yabdomen part);
Front shoe 6 positioning sub-step: find the maximum coordinate of the slice in the left chignon 1, defined as hoof 6 (x)The front hoof is a common hoof,yfront hoof)。
As an implementation mode, the relation between the body ruler and the key points is visually shown in the figure 4. In the step 6, the process is carried out,
the length of the body is the distance from chignon 1 to nojiri 3:
;
the oblique length of the body is the distance from the cattle nojiri 3 to the front end of the shoulder blade 4:
;
the depth of the abdomen is the distance from the back 2 to the abdomen 5:
;
height is the distance from chignon 1 to forehoof 6:
。
the invention uses the machine vision mode to measure the body size information of the cattle, greatly reduces the labor cost, and the mode belongs to non-contact type, does not cause any stress reaction to the cattle and has higher accuracy. The method has no equipment deployment requirement, can be used in systems of intelligent equipment such as mobile phones and the like, and can conveniently and quickly finish the body size measurement of the cattle only by using the mobile phone and the label paper which are carried about.
Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that changes, modifications, substitutions and alterations can be made in these embodiments without departing from the principles and spirit of the invention, the scope of which is defined in the appended claims and their equivalents.
- 上一篇:一种医用注射器针头装配设备
- 下一篇:一种基于双目视觉技术的刀闸智能识别系统及方法