Machine Vision Project Report
Machine Vision Project Report
Engineering
ACADEMIC SESSION 2013/2014
EEE 355 Robotics and Machine Vision
Mini project
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.
5.
5.0 Limitation
6.
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
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
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
3.0 Methodology
A. Inspection Flow Chart
Load the image from
computer
Convert to binary
image
XOR operation on
the images
Resultant image
where defect
detected
3|Page
Pixel [Image 2]
0
0
1
1
0
1
0
1
Pixel [Output
Image]
0
1
1
0
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
Explanation
Define the image matrix for im_gray
cvtColor(im_rgb,im_gray,CV_RGB2GRAY);
Mat result = img_bw_1^img_bw;
5|Page
7|Page
8|Page
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 !
10 | P a g e
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.
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
- http://stackoverflow.com/questions/1585535/convert-rgb-to-blackwhite-in-opencv
2. Load, Display and Save Image
- http://opencvexamples.blogspot.com/2013/09/opencv-example-toload-and-display-image.html#.U4lu8vmSz2P
3. Detection of Bare PCB Defects by Image Subtraction Method using
Machine Vision
- http://www.iaeng.org/publication/WCE2011/WCE2011_pp15971601.pdf
11 | P a g e
9.0 Appendix
#include<opencv2\opencv.hpp>
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");
= 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;
// Show
);
12 | P a g e
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("Defect.jpg",result);
waitKey(0);
keystroke in the window
return 0;
return 0;
}
13 | P a g e
// Wait for a