Abstract—Today, vision in the various industries. In this work,

 Abstract—Today, the machine vision system applications are increasing sharply. Reducing both hardware and software costs resulted in more deployment of intelligent systems based on computer vision in the various industries. In this work, designing an intelligent quality control system for vision inspection purposes in pharmaceutical industries has been investigated. Our proposed method is based on template pattern matching and Radon transform, and the aim is to count the number of blister cards of pills on the product line. The results clearly show that the proposed algorithm is capable to tackle this challenging issue.Visual inspection (VI) is a process of determining the degree of deviation from a given set of specifications. Visual inspection system (VIS) is a method of data acquisition, data analysis, quality control, electrical system control, and process control for a particular product, system or process. The main processes involved in a visual inspection system are: image acquisition, image de-noising, image enhancement, image segmentation, image feature selection and extraction, image classification, feature matching, decision making, display of results, and generation of controlling signals according to set values and parameters 1. The most important issues that should be considered to design and implementation of a machine vision system for vision inspection purposes are listed as follows:  Illumination system: Light source types, Intensity, Number of light sources  and  Angles. Camera: Interface, Accessories,  Resolution, Type, Throughput, Shutter types (rolling  or global shutter),  Shutter speeds and Number of cameras Lens: Manual/Automatic, Wide Angle /Telephoto, Material (Glass/Plastic), Fast/Slow,Variable/Fixed (Focal length), and Resolution.  Software: It can be generally classified into the six different categories such as the scene constraints, image acquisition, image pre-processing, image processing, machine vision justification, and the systematic considerations 2. In 2, the role and importance of the machine vision systems in the industrial applications are described. Such a machine includes systems and sub-systems, which of course depend on the type of applications and required tasks. In general, expected functions from a vision machine are the exploitation and imposition of the environmental constraint of a scene, the capturing of the images, analysis of those captured images, recognition of certain objects and features within each image, and the initiation of subsequent actions in order to accept or reject the corresponding objects. The key points in design and applications of a machine vision system are also presented in 2. Quality control and monitoring is of paramount importance in the pharmaceutical industry, thus requiring deployment of accurate and effective inspection systems. It is necessary to present a low cost automatic inspection system aimed at quality monitoring of pharmaceutical products on a production line 3. There are several applications that a vision inspection system  can be used in pharmaceutical industry such as: Pill counting and prescription verification Pill classification based on color and shape Tablet defects detection: chip, hole and crack Bottle classification based on color symbol Bottle filling level inspection Bottle cap inspection Label checking based on barcode and text/symbolsIn this paper, we proposed our novel pill blister card counting system based on template matching and Radon transform. This proposed model can be used in any pharmaceutical product line to implement smart quality check systems.      Figure 1 shows the flowchart of our proposed system for counting the number of blister cards. In this figure, the image I_in  is first received from the camera output video stream, and then a template pattern matching algorithm is applied to it. In this work, we used the Pearson’s correlation coefficient template matching (PCC TM) method for this purpose. If the algorithm fails to find a packet object, it waits for the next frame; otherwise, it estimates the mass center of the detected object, and applies a predefined mask with the dimensions W_m×H_m  and extracts the sub-image, I_M. In the next step, for increasing the accuracy of the proposed algorithm, some processing operations are applied to the sub-image (I_M). The resulting image, I_E is then fed to the Radon Transform. By analyzing the image resulting from Radon transform, the number of blister cards can be counted. In the following, we elaborate details on our proposed algorithm.In the beginning step of our proposed algorithm, it is necessary to localize a Pill package as the main landmark object in the whole input image. In this work, we use a template matching (TM) approach. TM plays an important role in many image processing applications. In a TM approach, it is sought the point in which it is presented the best possible resemblance between a sub image known as a template and its coincident region within a source image 4. There are a lot of methods for pattern and template matching 4-7 but for simplicity, we use correlation coefficient 5, 8-10 template matching to find a pill package in an input image. So we use Pearson’s correlation coefficient as below 5:The correlation coefficient can be interpreted as a correlation between a template image   (with average  ) and an input image   (with average  ) after both the template and the image have been z-normalized (it is rescaled so that its mean is zero and the standard deviation is one) 8. Illumination and contrast differences are thus eliminated before match quality is evaluated making the correlation coefficient an ideal measure of match when we want to ensure robustness for variations of pattern brightness and contrast. Our study shows that template matching based on the correlation coefficient can successfully identify potential target. After pill package localization, the sub image  is extracted to calculate its mass center (C_x,C_y) by the following equations 11, 12:  Now, based on extracted point(C_x,C_y), the bounding box with height B_H and width B_w is assigned to extract the target sub image. This image then should be used by some preprocessing algorithms before feeding into Radon transform.   There are many image transformations for the directional pattern image analysis, including Hough transform, Gabor filter banks 13, 14, and Radon transform 15-17. One of the strongest methods for handlingh directional images is the Radon transform. The radon function computes projections of an image matrix along specified directions. In fact, a projection of an input image is a set of line integrals. The Radon function computes the line integrals from multiple sources along parallel paths, or beams, in a certain direction. The beams are spaced one pixel unit apart. To represent an image, the Radon function takes multiple, parallel-beam projections of the image from different angles by rotating the source around the center of the image 16.In general, the Radon transform of f(x,y) is the line integral of f parallel to the y´-axis 16, 18, 19:In this work, we have also proposed our algorithm for counting blister packs based on using Radon capabilities. In order to clarify our main idea, the figure 2 is depicted. It shows three synthetic directional noisy images with the angle of rotation about 90-degree and their Radon transform, respectively. In this figure, it can clearly be seen that by analyzing each Radon transformation output around the mentioned angle, the number of black lines in each of these synthetic directional images can be obtained. We develop this idea to count all blister cards in a pill package.In the product line,  the pill packages are carried by a conveyor belt so they have been passed continuously in front of a camera. We use an industrial USB3 camera with a rolling shutter. In a rolling shutter sensor, the start and end of exposure on each row or column or individual pixel happens sequentially, so all the pixels are not exposed all at the same time. The effect will be noticed if the object is moving exactly as our experiment condition. Furthermore, in many cases, an external sensor such as an optical sensor is used to trigger the camera when a moving object is passed. The fine positioning of both sensor and camera according to the camera lens specifications can yield an excellent image capturing system, but the total hardware costs will be increased accordingly. To reduce the hardware costs, we avoid using external sensors and implement this as a software task. For this purpose, our proposed algorithm runs the TM algorithm for each captured frame. In the figure 3(a), a pill package is arriving in the defined ROI (green box), but since it is not fully inserted, the TM algorithm cannot detect an object. Therefore, according to the proposed algorithm in figure 1, it waits to receive a next frame. In figure 3(b), after some left shifting, the object is well fitted into our ROI and consequently at this time, the TM algorithm can detect an object (Red box). Now, the mass center of the detected object can be calculated and then it should be applied by a mask with the dimensions W_m×H_m. The extracted sub-image is shown in figure 3(c). Then by applying the appropriate preprocessing operations, it is the best time to use  Radon transform. The result of applying radon transform to the sub-image is depicted in the figure 4.  As shown in this figure, the estimated number of blister cards is equal exactly to its true number. The food and pharmaceutical industries have the highest standards of production in the world. In order to satisfy a uniformly optimized quality control system, the use of vision-based intelligent machines is inevitable in these industries. In this work, we proposed a new and strong method to count the number of blister cards in a pill package. In this method, we have used template matching and Radon transform to tackle this challenge. The simulation results entirely reflect the fact that the proposed system is operational in the real industrial environment.