Intelligent machine vision system and method for milking robot
Through the combination of intelligent machine vision system and robotic arm control system, real-time identification and precise positioning of cow teats are achieved, which solves the problems of high cost and low recognition rate of existing milking robots, and improves operating efficiency and farm benefits.
Patent Information
- Application Number
- CN202310417178.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-19
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2043-04-19
AI Technical Summary
Existing milking robots have high costs, low recognition rates, and need to optimize division of labor and collaboration, making it difficult to achieve efficient and convenient teat disinfection, medicinal bathing, and milking operations for dairy cows.
An intelligent machine vision system is designed, which consists of a control system, an image recognition system, a local area network and a robotic arm control system. It uses a binocular camera and the YOLOv5 image recognition algorithm to realize the transformation of pixels, images, cameras and world coordinate systems. The real-time identification and precise positioning of cow teats drives the robotic arm to perform milk brushing and cup-setting actions.
It improves the accuracy and stability of milking operations, reduces labor intensity, saves labor, reduces operating costs, and increases farm efficiency.
Smart Images

Figure 00000000_0000
Abstract
Description
Technical Field
[0001] The invention belongs to the cross-technical field of animal husbandry and mechanical and electronic engineering, and in particular relates to an intelligent machine vision system and method for a milking robot. Background Art
[0002] With the continuous acceleration of innovative technologies in the dairy industry, high-tech products are increasingly being used in pastures. How to more efficiently and conveniently disinfect the teats of dairy cows, perform medicinal baths, and ensure milking has become an increasingly hot topic. Therefore, for intelligent milking robots, vision has always been a very important way to perceive the outside world, and the design of the mechanical system of the interface between the milk brush and the milk cup and the robotic arm is an important part of it. At present, the development of milking robots is still in its early stages, and the existing defects are mainly concentrated in high cost, low recognition rate, and the overall division of labor and cooperation of milking robots needs to be optimized.
[0003] In production, milking robots need to be disinfected, cleaned, and milked, thereby greatly reducing the labor intensity of workers. During the milking process, the milking machine needs to accurately locate the position of the nipple and adjust the robot based on the position data to improve the accuracy and stability of the milking machine. In addition, in order to complete the milking of the cow's nipples, a reasonable roller brush design and reasonable placement of the milk cup are also required to facilitate the real-time grasping and removal of the milk cup, and a series of related designs; therefore, it is urgent to design a milking robot that can achieve the above operations. Summary of the invention
[0004] In view of the deficiencies in the prior art, the present invention designs an intelligent machine vision system and method for a milking robot.
[0005] An intelligent machine vision system for a milking robot is constructed from four parts: a control system, an image recognition system, a local area network, and a robotic arm control system. The control system is centered on a control panel and is used to send and receive relevant control instructions. The image recognition system includes a binocular camera for image acquisition, image enhancement, image processing, and image detection. The local area network is used as a carrier of various instructions and information for communication and transmission between each other, and is constructed from switches, network cables, and router hardware devices. The robotic arm control system sends the binocular camera to a designated location to complete relevant operations according to the relevant instructions of its core control system.
[0006] The image recognition system collects images and transmits them to the control system via the local area network. The control board in the control system transmits control instructions to the robotic arm control system based on the transmitted information, drives the robotic arm control system to work, and then controls the robotic arm to move the binocular camera fixed on it to the specified position, thereby realizing real-time recognition of the cow's nipples. The robotic arm moves to the designated position to start the milk brushing and cupping actions.
[0007] An intelligent machine vision method for a milking robot is implemented based on the intelligent machine vision system of the milking robot, and specifically includes the following contents:
[0008] Step 1: Use the image acquisition system to obtain the bovine nipple image, and establish four coordinate systems of pixel, image, camera and world based on the image;
[0009] The image is acquired by the image acquisition system. The image exists in the form of a matrix. The elements in the matrix are the pixels of the image, and the corresponding element values correspond to the pixel values. There are four coordinate systems in the imaging model of the camera, namely: pixel coordinate system ( o -uv), image coordinate system (O l -xy), camera coordinate system (O c -X c Y c Z c ) and the world coordinate system (O w -X w Y w Z w );
[0010] The pixel coordinate system ( o -uv) represents the position of the bovine nipple in the image, with the upper left corner of the image as the origin, the positive directions of the coordinate axes are horizontally to the right and horizontally downward, and the unit is pixel; in the pixel coordinate system, the coordinate (u, v) of the bovine nipple represents the bovine nipple in the uth row and vth column of the matrix;
[0011] The image coordinate system ( l -xy) is coplanar with the pixel coordinate system, which represents the projection of the bovine nipple on the image plane; the image coordinate system (O l -xy) takes the intersection of the optical axis and the imaging plane of the image as the origin, the x-axis and y-axis are parallel to the u-axis and v-axis, and the unit is millimeter (mm); the bovine nipple coordinates (x, y) in the image coordinate system represent the actual physical coordinates of the bovine nipple in the image;
[0012] The camera coordinate system ( c -X c Y c Z c ) Take the optical center of the camera as the origin, X c Axis and Y c The axes are parallel to the horizontal and vertical directions of the imaging plane, respectively. c The axis is the direction of the optical axis and is perpendicular to the imaging plane;
[0013] The world coordinate system ( w -X w Y w Z w) is determined artificially, and the origin and the direction of the coordinate axis of the world coordinate system are freely defined; the world coordinate system is the coordinate system where the center of the flange at the end of the robot arm is located, using the coordinate system (O w -X w Y w Z w ) indicates that the binocular camera is installed at the center of the flange at the end of the robot arm, that is, the camera coordinate system is also located at the center of the flange at the end of the robot arm and coincides with the world coordinate system, so there is no need to convert from the camera coordinate system to the world coordinate system;
[0014] Step 2: Using the principle that the corresponding sides of similar triangles are proportional, based on the coordinate system established in step 1 above, calculate the coordinate value of the bovine nipple in the world coordinate system;
[0015] Step 2.1: Identify the bovine nipple based on the YOLOv5 image recognition algorithm, and obtain its coordinates in the pixel coordinate system according to opencv;
[0016] The image recognition is divided into four tasks: one is classification, which distinguishes the targets of the bovine nipple and non-bovine nipple in each frame of the image recognized by the binocular camera in real time, and whether the bovine nipple is included in each frame of the image; the second is positioning, which quickly locates the position of a given bovine nipple in each frame of the real-time image; the third is detection, which locates the position of the bovine nipple and determines whether the threshold of the predicted target as the bovine nipple is higher than a given threshold. If it is higher than the specified threshold, it is determined to be a bovine nipple, otherwise it is not; the fourth is to determine which bovine nipple, or which non-bovine nipple target and scene each pixel belongs to;
[0017] The yolov5 single-stage algorithm is used to identify the bovine nipple, realizing the integration of alternative box generation and judgment;
[0018] First, the relevant images are acquired through the binocular camera, and then the convolutional neural network (CNN) is used to extract the target features. The next step is to perform feature fusion improvement, and then select the candidate boxes that are higher than the set threshold as the final pre-selected boxes, and then output the detection results. The "intersection-over-union ratio" is used to determine whether the detection results are correct.
[0019] Step 2.2: Use the principle of pinhole imaging and similar triangles to convert the pixel coordinate system coordinate value into the camera coordinate system coordinate value, that is, the world coordinate system;
[0020] The image coordinate system and the pixel coordinate system have different origins but are coplanar, and their measurement units are different; the homogeneous transformation relationship from the image coordinate system to the pixel coordinate system is obtained:
[0021]
[0022] Set O c O lis the focal length of the camera, and any point P(X w Y w Z w ) and the camera optical center O c Through the intersection point p(x,y) of the plane where the image coordinate system is located, the relationship between the image coordinate system and the camera coordinate system is obtained according to the proportional relationship between the corresponding sides of similar triangles:
[0023]
[0024] According to the above formula, the homogeneous coordinate form of the bovine nipple transformed from the image coordinate system to the camera coordinate system is obtained:
[0025]
[0026] In the intelligent machine vision system, the world coordinate system and the camera coordinate system coincide with each other, and the above transformation is used to transform the bovine nipple coordinates from the pixel coordinate system to the camera coordinate system, i.e., the world coordinate system;
[0027]
[0028] In the above formula, f x ,f y ,u0,v0 are the camera intrinsic parameters, which are determined by the structure of the camera itself, and the intrinsic parameters of each camera are also different; using Zhang Zhengyou's camera calibration method, the camera's intrinsic parameter matrix and camera distortion coefficient are obtained;
[0029] It is impossible to achieve the conversion from pixel coordinate system to camera coordinate system by only obtaining the camera internal parameters, so this recognition system introduces a binocular stereo vision system;
[0030] In the binocular stereo vision system, the left camera coordinate system is used as the world coordinate system. For any point P (X, Y, Z), the left and right camera planes O 11 , O 12 Imaging l (x l ,y l ), p r (x r ,y r ), and y l =y r , according to the proportion of corresponding sides of similar triangles:
[0031]
[0032] In the above formula, f is the focal length of the camera, B is the distance between the optical centers of the left and right cameras, and the coordinate values of the bovine nipple can be converted from the pixel coordinate system to the camera coordinate system, i.e., the world coordinate system, through the camera internal parameters, parallax, and transformation matrix;
[0033] Step 3: Set the image recognition system and the robotic arm control system as daemon processes in the main control board. The image recognition system and the robotic arm control system will automatically run after the main control board is turned on. When four nipples are recognized at the same time, the image recognition system calculates the coordinate values of the four nipples in the world coordinate system. Then the image recognition system stores the coordinate values of the four nipples in the world coordinate system in the specified file and sends a signal to the robotic arm control system process. After receiving the signal, the robotic arm control system process reads the coordinate values of the four nipples stored in the file. After reading the coordinate values, the robotic arm control system calls the library function of the robotic arm control and uses the local area network to send the coordinate values to the robotic arm control cabinet. The robotic arm moves to the specified position to start the milk brushing and cupping actions.
[0034] Beneficial technical effects of the present invention:
[0035] The present invention is applicable to the field of intelligent milking, and provides technical support and guarantee for completing the disinfection, cleaning and milking of dairy cow nipples, protecting the health of nipple ends, reducing the incidence of mastitis, and increasing milk production. After adopting this system, the physical labor of the staff will be greatly reduced, saving labor, solving the problem of insufficient manpower, reducing operating costs, improving ranch benefits, and having high economic value. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 An overall structural block diagram of an intelligent machine vision system of a milking robot according to an embodiment of the present invention;
[0037] Figure 2 The embodiment of the present invention uses an image acquisition system to obtain the geometric relationship of each coordinate system;
[0038] Figure 3 Schematic diagram of binocular stereo vision principle of an embodiment of the present invention;
[0039] Figure 4 Schematic diagram of image recognition principle of an embodiment of the present invention;
[0040] Figure 5 Block diagram of a machine vision system according to an embodiment of the present invention;
[0041] Figure 6 A flow chart of an intelligent machine vision method for a milking robot according to an embodiment of the present invention;
[0042] Figure 7 Schematic diagram of the control system circuit of the embodiment of the present invention;
[0043] Figure 8 A schematic diagram of the results of bovine nipple recognition according to an embodiment of the present invention. DETAILED DESCRIPTION
[0044] The present invention will be further described below in conjunction with the accompanying drawings and embodiments;
[0045] An intelligent machine vision system for a milking robot is shown in the attached Figure 1 As shown in the figure, it is composed of four parts: control system, image recognition system, local area network, and robotic arm control system; the control system is based on the Jetson Xavier NX control board, which is used to send and receive relevant control instructions. The machine vision system block diagram, control flow chart, and circuit schematic diagram involved are respectively shown in the attached Figure 5 , Attachment Figure 6 And attached Figure 7 As shown; the image recognition system includes a binocular camera for image acquisition, image enhancement, image processing and image detection, wherein the specific geometric relationship in the coordinate transformation model involved, the binocular stereo vision principle diagram, and the image recognition principle diagram are respectively as shown in the attached Figure 2 , Attachment Figure 3 And attached Figure 4 As shown; the local area network is used as a carrier of various instructions and information for communication and transmission between each other. It is built by switches, network cables, and router hardware devices; the robotic arm control system sends the binocular camera to the designated location to complete related operations according to the relevant instructions of its core control system;
[0046] The main control board is a Jetson Nano NX core board, which mainly includes two parts: a control system that controls the robot arm to reach a specified position to perform cupping action, and a control system that drives the milk brush motor to work; the relationship between the main control board and the robot arm driver and stepper motor driver circuit is as follows: Figure 7 shown.
[0047] The stepper motor is operated by the control of the stepper motor driver. The stepper motor driver is powered by 12V. The stepper motor driver is connected to the main control board using a common cathode connection, where the PUL- and DIR- pins are connected to the GND pin of the main control board, and the PUL+ and DIR+ pins are connected to the GPIO.22 and GPIO.23 pins of the main control board respectively.
[0048] The robot control system and the main control board LAN pin are connected to a local area network through a switch. The main control board uses twisted pair to transmit signals at the physical layer, IP protocol at the network layer, and TCP protocol at the transport layer to send the coordinate information of the nipple to the robot.
[0049] The image recognition system collects images and transmits them to the control system via the local area network. The Jetson Xavier NX control board in the control system transmits control instructions to the robotic arm control system based on the transmitted information, drives the robotic arm control system to work, and then controls the robotic arm to move the binocular camera fixed on it to the specified position, realizing real-time recognition of the cow's nipples.
[0050] In this example, the binocular camera model used in the recognition system is HBVCAM-4M2214HD-2V11; the stepper motor model used in the roller brush is CZ3457; its circuit schematic diagram is as follows Figure 7 As shown;
[0051] An intelligent machine vision method for milking robots, as shown in the attached Figure 6 The intelligent machine vision system based on the above-mentioned milking robot is implemented, and specifically includes the following contents:
[0052] Step 1: Use the image acquisition system to obtain the bovine nipple image, and establish four coordinate systems of pixel, image, camera and world based on the image;
[0053] In the computer world, an image is acquired using an image acquisition system. The image exists in the form of a matrix. The elements in the matrix are the pixels of the image, and the corresponding element values correspond to the pixel values. There are four coordinate systems in the camera imaging model, namely: pixel coordinate system ( o -uv), image coordinate system (O l -xy), camera coordinate system (O c -X c Y c Z c ) and the world coordinate system (O w -X w Y w Z w );
[0054] The pixel coordinate system ( o -uv) represents the position of the bovine nipple in the image, with the upper left corner of the image as the origin, the positive directions of the coordinate axes are horizontally to the right and horizontally downward, and the unit is pixel; in the pixel coordinate system, the coordinate (u, v) of the bovine nipple represents the bovine nipple in the uth row and vth column of the matrix;
[0055] The image coordinate system ( l -xy) is coplanar with the pixel coordinate system, which represents the projection of the bovine nipple on the image plane; the image coordinate system (O l -xy) takes the intersection of the optical axis and the imaging plane of the image as the origin, the x-axis and y-axis are parallel to the u-axis and v-axis, and the unit is millimeter (mm); the bovine nipple coordinates (x, y) in the image coordinate system represent the actual physical coordinates of the bovine nipple in the image;
[0056] The camera coordinate system ( c -X c Y c Z c ) Take the optical center of the camera as the origin, X c Axis and Yc The axes are parallel to the horizontal and vertical directions of the imaging plane, respectively. c The axis is the direction of the optical axis and is perpendicular to the imaging plane;
[0057] The world coordinate system ( w -X w Y w Z w ) is determined artificially, and the origin and the direction of the coordinate axis of the world coordinate system are freely defined; the world coordinate system is the coordinate system where the center of the flange at the end of the robot arm is located, using the coordinate system (O w -X w Y w Z w ) indicates that the binocular camera is installed at the center of the flange at the end of the robot arm, that is, the camera coordinate system is also located at the center of the flange at the end of the robot arm and coincides with the world coordinate system, so there is no need to convert from the camera coordinate system to the world coordinate system;
[0058] Step 2: Using the principle that corresponding sides of similar triangles are proportional, based on the coordinate system established in step 1 above, calculate the coordinate value of the bovine nipple in the world coordinate system;
[0059] Step 2.1: Identify the bovine nipple based on the YOLOv5 image recognition algorithm, and obtain its coordinates in the pixel coordinate system according to opencv;
[0060] The core of this system is dynamic image recognition, and the key to dynamic image recognition system is target detection. The target in this intelligent machine vision system is the cow's nipple.
[0061] This image recognition mode is mainly divided into four tasks: one is classification, which is to distinguish the targets of cow nipples and non-cow nipples in each frame of the image recognized by the binocular camera in real time, and to know whether the cow nipples are included in each frame of the image; the second is positioning, which is to quickly locate the position of a given cow nipple in each frame of the real-time image; the third is detection, which is to locate the position of the cow nipple and determine whether the threshold for predicting the target to be a cow nipple is higher than a given threshold. If it is higher than the specified threshold, it is determined to be a cow nipple, otherwise it is not; the fourth is to determine which cow nipple, or which non-cow nipple target and scene each pixel belongs to.
[0062] The dynamic image recognition of this system adopts the yolov5 single-stage algorithm, which is a target detection algorithm based on deep learning, realizing the integrated realization of alternative box generation and judgment. The image recognition principle diagram is as follows Figure 4 shown.
[0063] First, the binocular camera obtains the relevant images, and then the CNN (convolutional neural network) extracts the target features. The next step is to improve the feature fusion. Why is it fused? It is because if the receptive field is too large, small targets may be lost; if the receptive field is too small, large targets may not be captured. Therefore, it is necessary to fuse features to avoid the loss of relevant features. Then select the candidate box that is higher than the set threshold as the final pre-selected box, and then output the detection result.
[0064] The target detection evaluation index of this system is "Intersection Over Union" (IOU). What is "IOU"? "IOU" is a standard to measure the degree of overlap between two detection frames. Using IoU, we can determine whether the detection result is correct. The commonly used threshold is 0.5. If IoU>0.5, it is considered a correct detection, otherwise it is considered a wrong detection. The threshold used in this system is also 0.5.
[0065] The process of the interface between the dynamic image recognition system and the robotic arm control software is: the robotic arm control software reads the file stream of the target data obtained by the dynamic image recognition system in real time, and transmits the data to the robotic arm control system, and then moves it to the target position accurately.
[0066] Step 2.2: Use the principle of pinhole imaging and similar triangles to convert the pixel coordinate system coordinate value into the camera coordinate system coordinate value, that is, the world coordinate system;
[0067] The image coordinate system and the pixel coordinate system have different origins but are coplanar, and their measurement units are different; the homogeneous transformation relationship from the image coordinate system to the pixel coordinate system is obtained:
[0068]
[0069] Set O c O l is the focal length of the camera, and any point P(X w Y w Z w ) and the camera optical center O c Through the intersection point p(x,y) of the plane where the image coordinate system is located, the relationship between the image coordinate system and the camera coordinate system is obtained according to the proportional relationship between the corresponding sides of similar triangles:
[0070]
[0071] According to the above formula, the homogeneous coordinate form of the bovine nipple transformed from the image coordinate system to the camera coordinate system is obtained:
[0072]
[0073] In the intelligent machine vision system, the world coordinate system and the camera coordinate system coincide with each other, and the above transformation is used to transform the bovine nipple coordinates from the pixel coordinate system to the camera coordinate system, i.e., the world coordinate system;
[0074]
[0075] In the above formula, f x ,f y ,u0,v0 are the camera intrinsic parameters, which are determined by the structure of the camera itself, and the intrinsic parameters of each camera are also different; using Zhang Zhengyou's camera calibration method, the camera's intrinsic parameter matrix and camera distortion coefficient are obtained;
[0076] It is impossible to achieve the conversion from pixel coordinate system to camera coordinate system by only obtaining the camera internal parameters, so this recognition system introduces a binocular stereo vision system;
[0077] In the binocular stereo vision system, the left camera coordinate system is used as the world coordinate system. For any point P (X, Y, Z), the left and right camera planes O 11 , O 12 Imaging l (x l ,y l ), p r (x r ,y r ), and y l =y r , according to the proportion of corresponding sides of similar triangles:
[0078]
[0079] In the above formula, f is the focal length of the camera, B is the distance between the optical centers of the left and right cameras, and the coordinate values of the bovine nipple can be converted from the pixel coordinate system to the camera coordinate system, i.e., the world coordinate system, through the camera internal parameters, parallax, and transformation matrix;
[0080] Step 3: Set the image recognition system and the robotic arm control system as daemon processes in the main control board. The image recognition system and the robotic arm control system will automatically run after the main control board is turned on. When four nipples are recognized at the same time, the image recognition system calculates the coordinate values of the four nipples in the world coordinate system. The image recognition system then stores the coordinate values of the four nipples in the world coordinate system in the specified file and sends a signal to the robotic arm control system process. After receiving the signal, the robotic arm control system process reads the coordinate values of the four nipples stored in the file. After the robotic arm control system reads the coordinate values, it calls the library function of the robotic arm control and uses the local area network to send the coordinate values to the robotic arm control cabinet. The robotic arm moves to the specified position to start the milk brushing and cupping actions. The schematic diagram of the results of the recognition of the cow nipples is shown in the attached figure. Figure 8 shown.
Claims
1. An intelligent machine vision method for a milking robot is implemented based on an intelligent machine vision system of a milking robot, which is composed of four parts: a control system, an image recognition system, a local area network, and a mechanical arm control system. The control system is centered on a control panel for sending and receiving relevant control instructions. The image recognition system includes a binocular camera for image acquisition, image enhancement, image processing, and image detection. The local area network is used as a carrier of various instructions and information for communication and transmission between each other, and is constructed of switches, network cables, and router hardware devices. The mechanical arm control system sends the binocular camera to a designated position to complete relevant operations according to the relevant instructions of its core control system. The image recognition system acquires images and transmits them to the control system using the local area network. The control panel in the control system transmits control instructions to the mechanical arm control system based on the transmitted information, drives the mechanical arm control system to work, and then controls the mechanical arm to move the binocular camera fixed thereon to a designated position, thereby realizing real-time recognition of cow nipples. The mechanical arm moves to the designated position to start the milk brushing and cupping actions, characterized in that Specifically include the following: Step 1: Use the image acquisition system to obtain the bovine nipple image, and establish four coordinate systems of pixel, image, camera and world based on the image; An image is acquired using an image acquisition system. The image exists in the form of a matrix. The elements in the matrix are pixels of the image, and the corresponding element values correspond to pixel values. There are four coordinate systems in the camera imaging model: pixel coordinate system ( o -uv), image coordinate system (O l -xy), camera coordinate system (O c -X c Y c Z c ) and the world coordinate system (O w -X w Y w Z w ); Step 2: Using the principle that corresponding sides of similar triangles are proportional, based on the coordinate system established in step 1 above, calculate the coordinate value of the bovine nipple in the world coordinate system; Step 3: Set the image recognition system and the robotic arm control system as daemon processes in the main control board. The image recognition system and the robotic arm control system will automatically run after the main control board is turned on. When four nipples are recognized at the same time, the image recognition system calculates the coordinate values of the four nipples in the world coordinate system. Then the image recognition system stores the coordinate values of the four nipples in the world coordinate system in the specified file and sends a signal to the robotic arm control system process. After receiving the signal, the robotic arm control system process reads the coordinate values of the four nipples stored in the file. After reading the coordinate values, the robotic arm control system calls the library function of the robotic arm control and uses the local area network to send the coordinate values to the robotic arm control cabinet. The robotic arm moves to the specified position to start the milk brushing and cupping actions.
2. The intelligent machine vision method for a milking robot according to claim 1, characterized in that: The pixel coordinate system (O) described in step 1 o -uv) represents the position of the bovine nipple in the image, with the upper left corner of the image as the origin, the positive directions of the coordinate axes are horizontally to the right and horizontally downward, and the unit is pixel; in the pixel coordinate system, the coordinate (u, v) of the bovine nipple represents the bovine nipple in the uth row and vth column of the matrix; The image coordinate system ( l -xy) is coplanar with the pixel coordinate system, which represents the projection of the bovine nipple on the image plane; the image coordinate system (O l -xy) takes the intersection of the optical axis and the imaging plane of the image as the origin, the x-axis and y-axis are parallel to the u-axis and v-axis, and the unit is millimeter (mm); the bovine nipple coordinates (x, y) in the image coordinate system represent the actual physical coordinates of the bovine nipple in the image; The camera coordinate system ( c -X c Y c Z c ) Take the optical center of the camera as the origin, X c Axis and Y c The axes are parallel to the horizontal and vertical directions of the imaging plane, respectively. c The axis is the direction of the optical axis and is perpendicular to the imaging plane; The world coordinate system ( w -X w Y w Z w ) is determined artificially, and the origin and the direction of the coordinate axis of the world coordinate system are freely defined; the world coordinate system is the coordinate system where the center of the flange at the end of the robot arm is located, using the coordinate system (O w -X w Y w Z w ) represents; at the same time, the binocular camera is installed in the center of the flange at the end of the robot arm, that is, the camera coordinate system is also located in the center of the flange at the end of the robot arm and coincides with the world coordinate system, so there is no need to convert from the camera coordinate system to the world coordinate system.
3. The intelligent machine vision method for a milking robot according to claim 1, characterized in that: Step 2 is as follows: Step 2.1: Identify the bovine nipple based on the YOLOv5 image recognition algorithm, and obtain its coordinates in the pixel coordinate system according to opencv; The image recognition is divided into four tasks: first, classification, distinguishing the targets of bovine nipples and non-bovine nipples in each frame of the image recognized by the binocular camera in real time, and whether the bovine nipples are included in each frame of the image; The second is positioning, which quickly locates the position of a given bovine nipple in each frame of real-time image; the third is detection, which locates the position of the bovine nipple and determines whether the threshold of the predicted target being the bovine nipple is higher than a given threshold. If it is higher than the specified threshold, it is determined to be a bovine nipple, otherwise it is not; the fourth is to determine which bovine nipple each pixel belongs to, or which non-bovine nipple target and scene; The yolov5 single-stage algorithm is used to identify the bovine nipple, realizing the integration of alternative box generation and judgment; First, relevant images are acquired through a binocular camera, and then the convolutional neural network (CNN) is used to extract target features. The next step is to perform feature fusion improvement, then select the candidate boxes that are higher than the set threshold as the final pre-selected boxes, and then output the detection results; use the "intersection-over-union ratio" to determine whether the detection results are correct; Step 2.2: Use the principle of pinhole imaging and similar triangles to convert the pixel coordinate system coordinate value into the camera coordinate system coordinate value, that is, the world coordinate system; The image coordinate system and the pixel coordinate system have different origins but are coplanar, and their measurement units are different; the homogeneous transformation relationship from the image coordinate system to the pixel coordinate system is obtained: Set O c O l is the focal length of the camera, and any point P(X w Y w Z w ) and the camera optical center O c Through the intersection point p(x,y) of the plane where the image coordinate system is located, the relationship between the image coordinate system and the camera coordinate system is obtained according to the proportional relationship between the corresponding sides of similar triangles: According to the above formula, the homogeneous coordinate form of the bovine nipple transformed from the image coordinate system to the camera coordinate system is obtained: In the intelligent machine vision system, the world coordinate system and the camera coordinate system coincide with each other, and the above transformation is used to transform the bovine nipple coordinates from the pixel coordinate system to the camera coordinate system, i.e., the world coordinate system; In the above formula, f x ,f y ,u0,v0 are the camera intrinsic parameters, which are determined by the structure of the camera itself, and the intrinsic parameters of each camera are also different; using Zhang Zhengyou's camera calibration method, the camera's intrinsic parameter matrix and camera distortion coefficient are obtained; It is impossible to achieve the conversion from pixel coordinate system to camera coordinate system by only obtaining the camera internal parameters, so this recognition system introduces a binocular stereo vision system; In the binocular stereo vision system, the left camera coordinate system is used as the world coordinate system. For any point P (X, Y, Z), the left and right camera planes O 11 , O 12 Imaging l (x l ,y l ), p r (x r ,y r ), and y l =y r , according to the proportion of corresponding sides of similar triangles: In the above formula, f is the focal length of the camera, and B is the distance between the optical centers of the left and right cameras. The coordinate values of the bovine nipple can be converted from the pixel coordinate system to the camera coordinate system, i.e., the world coordinate system, through the camera internal parameters, parallax, and transformation matrix.
