Keywords

1 Introduction

Pleurotus eryngii is a kind of rare edible fungus, which is very popular among consumers. In the process of factory cultivation, Pleurotus eryngii should be inoculated in a sterile working environment and a highly efficient and stable inoculation process, otherwise it will lead to failure of inoculation or directly affect the quality of the mushroom [1].

At present, as shown in Fig. 1, most enterprises adopt the traditional manual inoculation method. Workers wearing protective clothing use buttons to control the operation of the conveyor belt to transfer the packed Pleurotus eryngotus medium to the appropriate location, and press the buttons to control the liquid strains to enter the syringe. However, the inoculation efficiency of Pleurotus eryngus was reduced due to the following three reasons: after a long period of inoculation, workers could not maintain the standard inoculation operation due to physical exhaustion; Because the temperature of the inoculation room is required to be kept at 25 ℃, the heat emitted by the workers themselves will cause adverse effects on the inoculation room. The optimal liquid strain content required for Pleurotus eryngii inoculation is 30 ml, so it is difficult to guarantee the precision of liquid strain injection by manual injection.

In order to solve the above problems, this paper designed a set of automatic control system for Pleurotus eryngii inoculation, which can replace manual automatic completion of Pleurotus eryngii inoculation, including PLC control, manipulator trajectory optimization and center positioning based on image recognition. By the simulation analysis, the system can not only effectively replace manual to complete the inoculation work, but also significantly improve the work efficiency.

Fig. 1.
figure 1

Traditional artificial Pleurotus eryngii inoculation

2 Design of Pleurotus Eryngii Inoculation Control System

The control system mainly includes four links, which are the start and stop of the conveyor belt, the opening and closing of the solenoid valve, the precise positioning of machine vision and the trajectory planning of the manipulator arm. The Culture medium of Pleurotus eryngii to be inoculated is placed in a box in groups of 12 and transported to the appropriate location by a conveyor belt. When the position sensor senses the frame, the conveyor belt stops moving. Due to the influence of external factors such as the delay of transmission signal and the skew bag of culture medium of Pleurotus eryngii, machine vision is used to collect images of culture medium of Pleurotus eryngii and find 12 central positions accurately. Next, they will be transmitted to the manipulator arm by the upper computer in turn. The function of the manipulator is to take the syringe and insert it into the culture medium of Pleurotus eryngus according to the spatial coordinates obtained from the image recognition. Finally, PLC accurately controls the injection amount of liquid strain to 30ml by controlling the start and stop time of the solenoid valve.

2.1 Design of Pleurotus Eryngii Inoculation Hardware System

It is well known that PLC has the advantages of high reliability, flexible configuration, convenient installation, fast running speed and so on [2]. Therefore, the hardware system of the automatic production line of Pleurotus eryngii inoculation designed in this paper uses PLC as the control processing unit. As is shown in Fig. 2, The hardware of the control system includes PC (personal computer), PLC, servo drives, servo motors, industrial camera, electromagnetic valve, cylinder, belt and mechanical arm device, such. According to the specified technological process, PLC controls each hardware equipment to cooperate with each other to realize the automatic production of Pleurotus eryngii inoculation.

Fig. 2.
figure 2

Structure of Pleurotus eryngii inoculation control system

After considering the control system performance, development cost and I/O points and other factors, this paper selects Siemens S7-1500 series PLC as the controller of the equipment, and chooses the CPU as 1516. CPU 1516 has 2 PROFINET ports (X1 P1/P2 and X2 P1) and 1 PROFIBUS port. X2 P1, as the slave access port, interacts with the data of the upper computer through the industrial Ethernet bus. X1 and P1, as the access ports of the device, realize PROFINET communication with touch screen, frequency converter, distributed I/O unit, manipulator and other modules through switches.

2.2 Design of Pleurotus Eryngii Inoculation Software System

The inoculation control software of Pleurotus eratus is developed on TIA Portal platform, mainly including the design of S7-1500 PLC control program, TP1200 touch screen interface and upper computer monitoring interface. The PLC program is used for the automatic control of Pleurotus eryngii inoculation production line and the response to the monitoring request of the console, touch screen and upper computer. The program control flow is shown in Fig. 3.

The specific work steps are as follows.

  • Put the baskets of Culture medium of Pleurotus eryngii to be inoculated on the running conveyor belt;

  • The sensor 1 senses the basket and sends a signal to the PLC, and records the number of baskets through the PLC;

  • The sensor 2 inducts the basket and sends a signal to the PLC, which stops the conveyor belt running;

  • Take pictures of 12 Culture medium of Pleurotus eryngii to be inoculated inside each basket by industrial camera, and upload them to PC;

  • Image processing is carried out on PC through MATLAB, all centroid coordinates are found, and coordinate values are transmitted to PLC through OPC (OLE for Process Control) protocol;

  • By PROFINET protocol, PLC transmits the centroid coordinates to the manipulator successively;

  • The mechanical arm accepts the centroid coordinates and drives the syringe to the centroid coordinates according to the program and sends a signal to inform the PLC;

  • PLC starts the solenoid valve and records the time T. When T is equal to the preset time T, stop the solenoid valve, that is, the injection task of 30 ml liquid strain has been completed;

  • The mechanical arm is reset and ready to receive the next coordinate point;

  • The PLC transmits the next coordinate point to the robot, and then returns to Step 6;

  • When the basket's Pleurotus eryngii medium has been inoculated, the conveyor belt is started for preparing the next basket for inoculation. Then, return to Step 3;

  • When the number of inoculated baskets is equal to the number of baskets sensed by sensor 1, the conveyor belt is stopped. Finally, complete the inoculation task.

Fig. 3.
figure 3

PLC program control flow chart

2.3 Improvement of Work Efficiency

In practical application, the control system should not only meet the requirements of control performance, but also improve work efficiency as much as possible. In the whole control system, the time of trajectory planning carried out by the manipulator operated syringe occupies more than half of the whole inoculation time, so it is of great significance to select the time optimization for the trajectory of the manipulator. Because the particle swarm optimization (PSO) algorithm has the characteristics of simple structure, easy implementation, easy parameter adjustment, and can directly choose the polynomial interpolation time as the variable to optimize the PSO algorithm [3], so the PSO algorithm is selected to optimize the trajectory of the manipulator.

Analysis of Quintic Polynomial Trajectory Planning Algorithm.

In order to reduce the vibration of the manipulator, the manipulator should meet the requirements of smoothness during operation. The solution of the quintic polynomial of joint Angle can satisfy the restriction of diagonally plus acceleration and avoid abrupt acceleration. Let the trajectory planning formula of joint Angle be:

$$ \theta \left( {\text{t}} \right) = a_{0} + a_{1} t + a_{2} t^{2} + a_{3} t^{3} + a_{4} t^{4} + a_{5} t^{5} $$
(1)

In the formula (1), \({\text{t}}\) represents time. \(\uptheta \left( {\text{t}} \right)\) represents the Angle varying with time. \({\text{a}}_{0} ,{\text{a}}_{1} ,{\text{a}}_{2} ,{\text{a}}_{3} ,{\text{a}}_{4} ,{\text{a}}_{5} { }\) represent the coefficients of the above formula. Set the initial time as 0, \({\uptheta }_{0}\) as the initial position, \({\text{t}}_{1}\) as the time when the end reaches the end, and \({\uptheta }_{1}\) as the end position, then the constraint conditions are as follows:

$$ \left\{ {\begin{array}{*{20}l} {\theta_{0} = a_{0} } \hfill \\ {\theta_{0} = a_{0} + a_{1} t_{1} + a_{2} t_{1}^{2} + a_{3} t_{1}^{3} + a_{4} t_{1}^{4} + a_{5} t_{1}^{5} } \hfill \\ {\dot{\theta }_{0} = a_{1} } \hfill \\ {\dot{\theta }_{1} = a_{0} + 2a_{2} t_{1} + 3a_{3} t_{1}^{2} + 4a_{4} t_{1}^{3} + 5a_{5} t_{1}^{5} } \hfill \\ {\ddot{\theta }_{0} = a_{0} } \hfill \\ {\ddot{\theta }_{1} = 2a_{2} + 6a_{3} t_{1} + 12a_{4} t_{1}^{2} + 20a_{5} t_{1}^{5} } \hfill \\ \end{array} } \right. $$
(2)

In the formula (2), \(\dot{\theta }_{0}\) represents velocity. \(\ddot{\theta }_{0}\) represents initial acceleration, final velocity \(\dot{\theta }_{1}\),\(\ddot{\theta }_{1}\) represents final acceleration. According to the formula (2), there are six formulas in total, and the values of six unknowns \(a_{0} ,a_{1} ,a_{2} ,a_{3} ,a_{4} ,a_{5}\). The results are shown in formula (3).

$$ \left\{ {\begin{array}{*{20}l} {a_{0} = \theta_{0} } \hfill \\ {a_{1} = \dot{\theta }_{0} } \hfill \\ {a_{2} = \frac{{\ddot{\theta }_{0} }}{2}} \hfill \\ {a_{3} = \frac{{20\theta_{1} - 20\theta_{0} - \left( {8\dot{\theta }_{1} + 12\dot{\theta }_{0} } \right)t_{1} - \left( {3\ddot{\theta }_{0} - 2\ddot{\theta }_{1} } \right)t_{1}^{2} }}{{2t_{1}^{3} }}} \hfill \\ {a_{4} = \frac{{30\theta_{0} - 30\theta_{1} - \left( {14\dot{\theta }_{1} + 16\dot{\theta }_{0} } \right)t_{1} - \left( {3\ddot{\theta }_{0} - 2\ddot{\theta }_{1} } \right)t_{1}^{2} }}{{2t_{1}^{4} }}} \hfill \\ {a_{5} = \frac{{12\theta_{1} - 12\theta_{0} - \left( {6\dot{\theta }_{1} + 6\dot{\theta }_{0} } \right)t_{1} - \left( {\ddot{\theta }_{0} - \ddot{\theta }_{1} } \right)t_{1}^{2} }}{{2t_{1}^{5} }}} \hfill \\ \end{array} } \right. $$
(3)

Trajectory Planning Simulation.

Particle Swarm Optimization (PSO) trajectory planning was simulated using MATLAB software. Set the population M as 100, the range of initial position as [0.1, 4], the range of initial velocity as [−2, 2], and the number of iterations as 100. In order to reduce amount of calculation of PSO algorithm, differential time is chosen as the optimization function, its fitness function \(f\left( t \right) = min\mathop \sum \nolimits t\).

Shi and Eberhart studied the inertial weight W and proposed a particle swarm optimization algorithm with W decreasing linearly as the number of iterations increases. This algorithm can quickly determine the optimal target azimuth in the initial optimization process. With the increase of the number of iterations, the value of W gradually decreases and the optimization is carried out in this azimuth.

$$ {\text{w}} = {\text{w}}_{{{\text{max}}}} - \left( {{\text{w}}_{{{\text{max}}}} - {\text{w}}_{{{\text{min}}}} } \right) \times \frac{{\text{k}}}{{{\text{k}}_{{{\text{max}}}} }} $$
(4)

In the above formula, \(w_{max}\) refers to the maximum inertial weight, \(w_{max} = 0.9\),\(w_{min}\) refers to the minimum inertial weight,\({ }w_{min} = 0.4\), and \(k_{max}\) refers to the maximum number of iterations. In order to prevent particles from running out of the solution space for optimization, a maximum value,\({ }V_{max}\), is set such that \(V_{k} \le V_{max}\). When \(V_{k} > V_{max}\); set \(V_{k} = V_{max}\).

The 3-5-3 interpolation trajectory planning algorithm can not only solve the problems of polynomial interpolation, such as second-order polynomial interpolation, no convex hull and difficulty in optimization, but also reduce the computational difficulty and improve the efficiency [4]. Let the 3-5-3 polynomial be:

$$ \left\{ {\begin{array}{*{20}c} {\uptheta _{{{\text{j}}1 \,=\, {\text{a}}_{{{\text{j}}13}} {\text{t}}^{3} + {\text{a}}_{{{\text{j}}12}} {\text{t}}^{2} + {\text{a}}_{{{\text{j}}11}} {\text{t}} + {\text{a}}_{{{\text{j}}10}} }} } \\ {\uptheta _{{{\text{j}}2 \,=\, {\text{a}}_{{{\text{j}}25}} {\text{t}}^{5} + {\text{a}}_{{{\text{j}}24}} {\text{t}}^{4} + {\text{a}}_{{{\text{j}}23}} {\text{t}}^{3} + {\text{a}}_{{{\text{j}}22}} {\text{t}}^{2} + {\text{a}}_{{{\text{j}}21}} {\text{t}} + {\text{a}}_{{{\text{j}}20}} }} } \\ {\uptheta _{{{\text{j}}3 \,=\, {\text{a}}_{{{\text{j}}33}} {\text{t}}^{3} + {\text{a}}_{{{\text{j}}32}} {\text{t}}^{2} + {\text{a}}_{{{\text{j}}31}} {\text{t}} + {\text{a}}_{{{\text{j}}30}} }} } \\ \end{array} } \right. $$
(5)

The angles corresponding to the initial positions, path points and end points of joints 1–3 are shown in Table 1.

Table 1. Angular interpolation points in joint space

MATLAB was used to simulate joints 1, and the results were shown in Figs. 4 and 5.

Fig. 4.
figure 4

Change curves of Angle, angular velocity and angular acceleration of joint 1

Fig. 5.
figure 5

Change curve of fitness value of joint 1

In Fig. 4, the change curves of Angle and angular velocity are relatively smooth, and there is no abrupt change in acceleration, indicating that the manipulator runs smoothly. In Fig. 5, the fitness value of the function decreases with the increase of the number of iterations, indicating that the total interpolation time of joint trajectory obtained at the end of iteration is the minimum.

3 Central Positioning

3.1 Image Acquisition

Figure 6 shows the image processing experimental platform built, which firstly studies a single Culture medium of Pleurotus eryngii to be processed. The industrial camera is fixed on the end of the manipulator arm through a clamp and moves along with the end of the manipulator arm, In the eye-in-hand mode. Given a camera calibration position, the manipulator moves to the calibration position before the camera takes pictures. The pictures taken by the industrial camera are uploaded to the PC, and the result after cropping is shown in Fig. 7.

Fig. 6.
figure 6

Image processing experimental platform

Fig. 7.
figure 7

Picture of Pleurotus eryngii culture medium to be inoculated

3.2 Image Processing

Image Grayscale Processing.

The grayscale processing of color images refers to the conversion of color images to grayscale images, that is, according to the color component RGB of the image into the grayscale value of the brightness range is (0, 255), so as to reflect the morphological characteristics of the image. According to the different sensitivity of human eyes to red, green and blue colors, the weighted average method is used for gray processing. According to the different sensitivity of human eyes to colors, different weights are given to RGB, and then the weighted average value of RGB brightness is taken as the gray value, as shown in formula (6).

$$ gray\left( {i,j} \right) = 0.3R\left( {i,j} \right) + 0.59G\left( {i,j} \right) + 0.11B\left( {i,j} \right) $$
(6)

MATLAB was used for simulation, and the results were shown in Fig. 8.

Fig. 8.
figure 8

Grayscale processing results

Image Segmentation.

Maximum inter-class variance method is a typical image segmentation method proposed by Japanese scholar Otsu in 1978 based on the principle of least square method, also known as Otsu method, abbreviated as Otsu. The measurement standard adopted in the OTSU algorithm is the maximum inter-class variance, whose principle is to obtain the inter-class variance between the target and the background through the threshold value. The larger the inter-class variance is, the greater the difference between the two parts of the image is, which means the minimum misclassification probability between the target and the background [5].

The calculation steps are as follows:

  • Assume that the range of gray value I in the image is \(\left[ {0,L - 1} \right]\), the pixel of gray value \( i\) is \(n_{i}\) and the total number of pixels is \( N\), then

    $$ N = \sum\nolimits_{i = 0}^{L - 1} {n_{i} } $$
    (7)

Set the probability of occurrence of grayscale value as \(p_{i}\), then

$$ p_{i} = \frac{{n_{i} }}{N} $$
(8)
  • Assume that the range of gray value of background region and target region is \(\left[ {0,T - 1} \right]\) and \( \left[ {T,L - 1} \right]\) respectively, and the probability of background region and target region is \(P_{0}\) and \(P_{1}\) respectively, then

    $$ P_{0} = \sum\nolimits_{i = 0}^{T - 1} {p_{i} } $$
    (9)
    $$ P_{1} = \sum\nolimits_{i = T}^{L - 1} {p_{i} } $$
    (10)
  • Calculate the average gray scale of the background area and the target area, respectively expressed by \(\mu_{0}\) and \(\mu_{1}\), then

    $$ \mu_{0} = \frac{1}{{P_{0} }}\sum\nolimits_{i = 0}^{T - 1} {\left( {i \times p_{i} } \right) = \frac{\mu \left( T \right)}{{P_{0} }}} $$
    (11)
    $$ \mu_{1} = \frac{1}{{P_{1} }}\sum\nolimits_{i = T}^{L - 1} {\left( {i \times p_{i} } \right) = \frac{\mu - \mu \left( T \right)}{{1 - P_{0} }}} $$
    (12)
  • Set the average grayscale of the image to \(\mu\), then

    $$ \mu = \sum\nolimits_{i = 0}^{L - 1} {\left( {i \times p_{i} } \right) = } \sum\nolimits_{i = 0}^{T - 1} {\left( {i \times p_{i} } \right) + \sum\nolimits_{i = T}^{L - 1} {\left( {i \times p_{i} } \right) = P_{0} \mu_{0} + P_{1} \mu_{1} } } $$
    (13)
  • Let the total variance of the region be \(\sigma_{i}^{2}\), then

    $$ \sigma_{i}^{2} = P_{0} \times \left( {\mu_{0} - \mu } \right)^{2} + P_{1} \times \left( {\mu_{1} - \mu } \right)^{2} $$
    (14)

MATLAB was used to simulate Fig. 8, and the results were shown in Fig. 9.

Fig. 9.
figure 9

Image segmentation results

Image Segmentation Optimization Based on Genetic Algorithm.

Although the maximum inter-class variance method can be used to obtain an appropriate threshold for image segmentation, the need to select \( K\) value from the gray scale range \(\left[ {0,L - 1} \right]\) leads to a large amount of calculation and a long time. Genetic algorithm (GA) is used to optimize the maximal class inter-square method, which can quickly find the optimal threshold [6]. Combined with the principle of the maximum inter-class variance method in Sect. 3.1, the use of genetic algorithm is to quickly find the \(T\) value that maximizes \(\sigma_{i}^{2}\).

The use of genetic algorithm is mainly divided into the following four stages:

  • Population initialization

    In population initialization, \(n\) chromosomes and \(m{ }\) genes need to be created. Each chromosome consists of m genes and represents a solution for each generation. Since the gray value range of the image is \(\left[ {0,255} \right]\), which corresponds to 8-bit binary number, if \(m = 8\), as shown in Fig. 10, the chromosome is encoded, and there are \({ }2^{8}\) situations on each chromosome. Let's say there are 10 solutions in each generation. Let's say \({ }n = { }10\).

Fig. 10.
figure 10

Chromosome coding map

  • Fitness assessment

    After population initialization, fitness function should be established to evaluate the fitness of each chromosome, that is, the performance of the solution. In this section, the maximum inter-class variance method is taken as the core, so \(F_{i} = \sigma_{i}^{2}\) is selected as the fitness function, where \(i = 1,2, \cdots ,10.\) The larger the \(F_{i}\) value of fitness is obtained, the more suitable the chromosome is.

  • Duplication

    The process is mainly divided into three parts: selection, crossover and mutation.

    Firstly, the optimal solution from the previous generation population was copied to the next generation. According to the Roulette Wheel Selection method, the probability of chromosome Selection was set as \(P_{i} \), and the following results were obtained:

    $$ P_{i} = \frac{{F_{i} }}{{\mathop \sum \nolimits_{i}^{n} F_{i} }} $$
    (15)

According to formula (15), a chromosome with a higher fitness \(F_{i} \) value has a higher probability of \(P_{i}\), which means that it is more likely to be selected in the population. Finally, through 10 random screening, the next generation group was selected.

In order to speed up the solving speed of the optimal threshold, gene exchange was carried out on some chromosomes, and the selection crossover probability was 0.7. In order to avoid falling into the trap of local optimal solution, the chromosome mutation operation is selected, that is, the gene in the chromosome is changed, and the probability of selection mutation is 0.4.

  • Decode

    The chromosome with the largest \(F_{i} \) fitness value was selected from the last generation and decoded into a decimal number, which is the optimal threshold T.

    The calculation process is shown in Fig. 11.

Fig. 11.
figure 11

Genetic algorithm to optimize the optimal threshold solution flow chart

MATLAB was used to optimize and simulate the genetic algorithm in Fig. 6, and the results were shown in Figs. 12 and 13, which were the optimal adaptive value evolution curve and the optimal threshold evolution curve respectively.

Fig. 12.
figure 12

Evolution curve of optimal fitness value

Fig. 13.
figure 13

Evolution curve of optimal threshold

As can be seen from Figs. 12 and 13, the fitness value of the genetic image was relatively small at the beginning of the inheritance. With continuous evolution, the unsuitable chromosomes were eliminated, and the fitness value became higher and higher, and the optimal threshold was found at the fifth generation of evolution. Through many simulations, it is found that the optimal threshold can be obtained by no more than 15 generations of evolutionary algebra. Therefore, according to the simultaneous calculation of 10 chromosomes in each generation, the optimal threshold value can be obtained within 150 threshold calculations. Compared with the traditional OTSU, which requires 256 thresholds to be calculated to compare the regional total variance, the calculation efficiency is improved by 70%.

To Solve the Center of Mass.

Taking Fig. 9 as the research object, the target region we required to be solved is in the middle, but there are most interference regions outside the target region, and the centroid coordinates of the target region can be solved only if the interference region is removed.

The image connectivity domain includes four neighborhood connectivity and eight neighborhood connectivity. Since eight neighborhood connectivity is used to identify whether there are pixels (white) in eight directions of a pixel point in a binary image, eight-neighborhood connectivity is more comprehensive and has good generality [7]. In this paper, eight-neighborhood connectivity is used to remove white interference areas. The operation process is shown in Fig. 14. In the above way, imclear Border function in MATLAB was used in this paper to clear the white interference area connected with the boundary, and the result is shown in Fig. 15-a. As can be seen from Fig. 15-a, the peripheral white area of the central target area has been cleared, but many small white interference areas are still left.

Set up the image of the target area for the \(P\), \(P = \left\{ {P_{1} ,P_{2} , \cdots ,P_{n} } \right\}\), \(P_{1} ,P_{2} , \cdots ,P_{n}\) respectively represented in Fig. 15-a white area. Let the areas of \(P_{1} ,P_{2} , \cdots ,P_{n}\) be \(s_{1} ,s_{2} , \cdots ,s_{n}\) respectively. Through calculation, the white region with the largest area is retained. Through simulation, the results are shown in Fig. 15-b.

Fig. 14.
figure 14

Oundary white interference area clearance flow chart

As shown in Fig. 15-b, there are some small black spots inside the target region. In order to improve the accuracy of centroid solution, image expansion algorithm is used to remove the black spots.

Let \(A\) be the object to be processed and \(B\) be the structural element. The structural element B is used to scan all pixel points of image \(A\), that is, the origin of \( B\) is used as the coordinate to scan each pixel point of \( A\). If A pixel point in \( A\) is 1 when \(B\) covers the region of \(A\), the corresponding pixel point of \(B\) is also 1, then the scanning point is 1;

$$ A \oplus B = \{ x|\hat{B}_{x} \cap A \ne \varnothing \} $$
(16)

In formula (16), \(\hat{B}\) is the mapping of \( B\) to \(A\), \(\hat{B}_{x}\) said image \( B\) shift distance along the vector \(x\). Through simulation, the result is as shown in Fig. 15-c, and the black spots have been removed.

Fig. 15.
figure 15

Binary image interference region processing results

Calculate Coordinates by means of the Mean Value.

According to Fig. 10-c, the small black points in the target area have all disappeared. Next, the coordinate of the center point of the target area is solved. Let the horizontal and vertical coordinates of the center point be X and Y respectively, and the horizontal and vertical coordinates of the target region be m and n respectively, then:

$$ X = \frac{{\mathop \sum \nolimits_{{\left( {m,n} \right) \in S}} x_{{\left( {m,n} \right)}} }}{S} $$
(17)
$$ Y = \frac{{\mathop \sum \nolimits_{{\left( {m,n} \right) \in S}} y_{{\left( {m,n} \right)}} }}{S} $$
(18)

\(x_{{\left( {m,n} \right)}}\) and \(y_{{\left( {m,n} \right)}}\) respectively represent the horizontal and vertical coordinates of the pixel points in the target region. S represents the area of the target region. According to Eqs. (17) and (18), the horizontal and vertical coordinates of the pixels in the target region are respectively added and then divided by the total area of the target region to obtain the horizontal X and vertical Y of the center point MATLAB is used for simulation, and the result is shown in Fig. 16. The coordinate position has been marked in the central area, and the coordinate point is (241, 191).

Fig. 16.
figure 16

Target area center point diagram

3.3 Multi-target Identification and Verification

In a practical production line, as shown in Fig. 17-a, in order to speed up the inoculation efficiency, 12 eryngii in a basket need to be identified simultaneously. The algorithm described above is used to simulate Fig. 17-a, and the result is shown in Fig. 17-b to obtain 12 target regions.

Fig. 17.
figure 17

Image processing of whole basket of Culture medium of Pleurotus eryngii

Set and the target area for \(Q = \left\{ {Q_{1} ,Q_{2} , \cdots ,Q_{12} } \right\}\), the area of it: \(S = \left\{ {S_{1} ,S_{2} , \cdots ,S_{12} } \right\}\), the center coordinates of it: \(O = \left\{ {O_{1} ,O_{2} , \cdots ,O_{12} } \right\}\), \({ }O_{i} = \left( {x_{i} ,y_{i} } \right)\), \(i = 1,2, \cdots ,12\). The steps for solving the central coordinates are as follows:

  • Calculate the number of connected domains and mark each connected domain;

  • Find the area of each connected domain S;

  • Find the sum of the abscissa and ordinate of each connected domain;

  • The sum of the abscissa and the sum of the ordinate of each connected domain is divided by the area to get the central coordinate of the connected domain \(O_{i}\).

Through simulation, the result is shown in Fig. 18. The central coordinates of all target regions have been worked out.

Fig. 18.
figure 18

Image processing results of a whole basket of Pleurotus eryngii

4 Conclusion

This paper presents a set of automatic control system for Pleurotus eryngii inoculation. The control part of the system mainly includes PLC control, mechanical arm control and visual control. Among them, PLC, as the upper computer, controls the operation of the entire Pleurotus eryngii inoculation production line to ensure that each link is completed normally according to the steps. In order to improve the running efficiency of the production line, the PSO method was used to optimize the trajectory of the manipulator. Through simulation analysis, it was found that the algorithm could reduce the running time of the manipulator. In order to improve the accuracy of inoculation by robotic arm, image recognition technology was used to accurately locate the culture medium of Pleurotus eryngii to be inoculated. Among them, the genetic algorithm is used to optimize the maximum inter-class variance method for image segmentation, and the simulation results show that the target region recognition accuracy can be reduced and the computational efficiency can be improved. Finally, the whole basket of Culture medium of Pleurotus eryngii to be processed was simulated, and 12 centroid coordinates were accurately obtained by means of the mean value method.