School of Electrical &Electronic
Engineering
ACADEMIC SESSION 2013/2014
EEE 355 Robotics and Machine Vision
Mini project
PCB Defects detection
Name : VINCENT KOK CHIN KEONG ([Link]@[Link])
MATRIC NO. : 112195
Date of submission : 3rd june 2014
SUPERVISED BY: Dr. khoo bee ee
Table of contents
Chapter
Description
1.
1.0 Abstract
2.
2.0 Introduction
3.
3.0 Methodology
A. Inspection Flow Chart
B. Image Subtraction Operation
C. OpenCV function used
4.
4.0 Results and Discussion
5.
5.0 Limitation
6.
6.0 Future Improvements
7.
7.0 Conclusion
8.
8.0 References
9.
9.0 Appendix
Page
1
2
3-5
6 - 10
11
11
11
11
12 - 13
EEE 355 Robotics & Machine Vision
1.0 Abstract
The main objective of this project is to let students apply the image processing techniques
that been taught in class in a given conditions based on their title. This particular project
involved the detection of the defect exist in a PCB board. A Printed Circuit Board (PCB) is a
circuit board consists of electronics components mounted on the surface. Basically, to
produce a perfect bare PCB board, inspection of PCB is necessary to reduce defects. We
apply the machine vision concept to inspect the bare PCB. We first compare a standard PCB
image with a PCB image to be inspected using a simple subtraction algorithm that can
detect the defected region. Our focus is to detect the defect on the PCB, such as broken
track. There are so many algorithms out there to detect the defect on the PCB board.
1|Page
EEE 355 Robotics & Machine Vision
2.0 Introduction
Nowadays, PCB manufacturing is getting more and more important for the electronics
industry such as mobile phones, tablets, washing machines and prototyping boards. Hence,
it is very important to have machine vision inspection of the PCB to improve the quality of
the PCBs. As you know, in manufacturing industry, there are errors such as defects,
misalignment and orientation error. Hence we need automated inspection to analysed for
the errors. There are plenty of such algorithms out there now.
There are 3 main processes in inspection of PCBs : defect detection, defect classification,
and the location of the defect.
Of course, automated inspection system is better than human inspection in which
subjectivity, fatigue, slowness and high cost is involved. The technology is moving very fast
and hence a fast and efficient inspection system is required to make sure 100% quality PCBs
are produced. These conclude that automated systems are preferred in manufacturing
industry nowadays for higher productivity.
In my case study, I am going to investigate about how to detect a broken track on the PCB.
This project required us to only use the images captured by the laboratory camera or our
own digital camera devices. In this project, Visual Studio C++ 2010 was used as the main
compiler with linked libraries to the OpenCV image processing library.
2|Page
EEE 355 Robotics & Machine Vision
3.0 Methodology
A. Inspection Flow Chart
Load the image from
computer
Convert the images
to grayscale image
Threshold the image
Convert to binary
image
XOR operation on
the images
Resultant image
where defect
detected
3|Page
EEE 355 Robotics & Machine Vision
B. Image Subtraction Operation
Well, this is the simplest algorithm that we can find to detect the
difference between the two images, i.e. to detect the defect on the PCB. In other word,
image subtraction is performed in order to get the difference between two images. In
this algorithm, we need to use two images reference image and the inspected image.
In this method, we compare both the images pixel-by-pixel using XOR logic
operator. After performing the operation, we will get the resulting image that consist of
the defects. The subtract operation produces either negative or positive pixel value.
Therefore the outcome of this operation is divided into negative image and positive
image.
Pixel [Image 1]
Pixel [Image 2]
0
0
1
1
0
1
0
1
Pixel [Output
Image]
0
1
1
0
The overview of the XOR/Subtraction operation process is shown below :
To perform the image subtraction operation, it is required that both images has same size in
terms of pixels. The logical XOR operation will show us the defect in inspected image as
compared with reference image
4|Page
EEE 355 Robotics & Machine Vision
C. OpenCV Functions Used
OpenCV function
Mat im_gray;
Explanation
Define the image matrix for im_gray
Mat im_rgb = imread("PCB_no_defect.tif");
Load the image PCB_no_defect.tif from
the disk and read it as RGB image.
Convert the RGB image read to grayscale
image.
Define the image matrix for result. The result
is obtained by XOR the reference image with
defected image.
Create a window for display. The name of
the window is Display window1. The
window size is made to adjust automatically
according to the size of image.
Show the image result at Display
window1
Write the image result to the project
folder.
cvtColor(im_rgb,im_gray,CV_RGB2GRAY);
Mat result = img_bw_1^img_bw;
namedWindow( "Display window1",
WINDOW_AUTOSIZE );
imshow( "Display window1", result);
imwrite("[Link]",result);
5|Page
EEE 355 Robotics & Machine Vision
4.0 Results And Discussion
A) Top Lighting
RGB Image ( Reference image )
Grayscale Image (Reference Image )
6|Page
RGB Image ( Defected image )
Grayscale Image (Defected Image )
EEE 355 Robotics & Machine Vision
Binary Image (Reference Image )
Binary Image (Defected Image )
Resultant image ( Defect detected)
7|Page
EEE 355 Robotics & Machine Vision
B) Top and 2 Sides Lighting
RGB Image ( Reference image )
Grayscale Image (Reference Image )
8|Page
RGB Image ( Defected image )
Grayscale Image (Defected Image )
EEE 355 Robotics & Machine Vision
Binary Image (Reference Image )
Binary Image (Defected Image)
Resultant image ( Defect detected)
9|Page
EEE 355 Robotics & Machine Vision
As you can see from the result, we first load the RGB image, both reference and defected
image. Next we will then grayscale both image. The reason for differentiating such images
from any other sort of colour image is that less information needs to be provided for each
pixel. In fact a `gray' colour is one in which the red, green and blue components all have
equal intensity in RGB space, and so it is only necessary to specify a single intensity value for
each pixel, as opposed to the three intensities needed to specify each pixel in a full colour
image.
Next, we convert the grayscale image to binary image that consist only binary pixel 1 or 0
for easy operation process later on.
Now, after we get both the binary image, we perform the XOR operation to detect the
defected region on the image.
If there is no defect detected, the window will show as below :
No defects detected !
Comparison between two different lighting
As you can see from the result of two different lighting A) Top Lighting and B) Top and 2
Sides Lighting, the result is kind deviate a little under different lighting with constant
threshold value of 138. The result for B) are subjected to more noise. However, both the
type of lighting are able to detect the defect and show it at the final result.
10 | P a g e
EEE 355 Robotics & Machine Vision
5.0 Limitations
This image subtraction algorithm actually has a lot of disadvantages and limitations :
It only can detect for the broken track but cannot detect like short circuit, missing
components.
The images size must be the same (i.e. the reference image and defected image
must have same size)
Both the inspected image and reference image must have the same orientation.
6.0 Further Improvement
This project can be further improved by upgrading defect detection algorithm to suit a
variety of lighting conditions. Besides, we could improve the algorithm to detect different
kind of defects such as missing components or short circuits. Improvement can be made on
stating the location for the defect and calculate the size of the defect.
7.0 Conclusion
In conclusion, we manage to complete the project with a great success in testing and
coding for the defect detection on the bare PCB. Indeed, throughout this project, we have
learnt how to use the OpenCV library in Visual Studio C++ 2010. We were also exposed to
the effects of different kind of lighting condition which could affect the performance of the
algorithm.
This project enable us to apply the knowledge and theory that we learnt in class to solve
real life problems.
8.0 Reference
1. Convert RGB to Black & White in OpenCV
- [Link]
2. Load, Display and Save Image
- [Link]
3. Detection of Bare PCB Defects by Image Subtraction Method using
Machine Vision
- [Link]
11 | P a g e
EEE 355 Robotics & Machine Vision
9.0 Appendix
#include<opencv2\[Link]>
using namespace cv;
int main ( int argc, char **argv )
{
Mat dst;
Mat im_gray;
Mat im_gray_1;
//Mat im_gray = imread("PCB_no_defect.tif",CV_LOAD_IMAGE_GRAYSCALE);
Mat im_rgb
= imread("PCB_no_defect.tif");
//Mat im_gray_1 = imread("PCB_defect.tif",CV_LOAD_IMAGE_GRAYSCALE);
Mat im_rgb_1
= imread("PCB_defect.tif");
cvtColor(im_rgb,im_gray,CV_RGB2GRAY);
cvtColor(im_rgb_1,im_gray_1,CV_RGB2GRAY);
equalizeHist( im_gray, dst );
Mat img_bw = im_gray > 138;
Mat img_bw_1 = im_gray_1 > 138;
Mat result = img_bw_1-img_bw;
namedWindow( "Display window1", WINDOW_AUTOSIZE );// Create a window
for display.
imshow( "Display window1", result);
// Show
namedWindow( "Display window2", WINDOW_AUTOSIZE );// Create a window
for display.
imshow( "Display window2",img_bw
inside it.
);
// Show our image
namedWindow( "Display window3", WINDOW_AUTOSIZE );// Create a window for
display.
12 | P a g e
EEE 355 Robotics & Machine Vision
imshow( "Display window3", img_bw_1);
imwrite("im_gray.jpg", im_gray);
imwrite("im_gray_1.jpg", im_gray_1);
imwrite("im_bw.jpg", img_bw);
imwrite("im_bw_1.jpg", img_bw_1);
imwrite("[Link]",result);
waitKey(0);
keystroke in the window
return 0;
return 0;
}
13 | P a g e
// Wait for a