반응형

Detecting a semiconductor wafer by Hough transform.

원형인 반도체 Wafer를 감지 한다. 배경에 노이즈가 많으면 오감지 가능성이 커진다.


작성 중.............



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <opencv2/opencv.hpp>
 
using namespace std;
using namespace cv;
 
int main(int argc, char** argv)
{
    VideoCapture cap(0);
 
    if (!cap.isOpened()) {
        cerr << "Camera open failed." << endl;
 
        return 0;
    }
    
    int frameWidth = (int)cap.get(CAP_PROP_FRAME_WIDTH);
    int frameHeight = (int)cap.get(CAP_PROP_FRAME_HEIGHT);
 
    Mat frame, grayed, blurred;
    
    string textWafer = "Wafer detected";
    string textNoWafer = "No wafer detected";
    // Size cv::getTextSize(const String & text, int fontFace, double fontScale, int thickness,    int* baseLine)
    Size textSizeWafer = getTextSize(textWafer, FONT_HERSHEY_SIMPLEX, 12NULL);
    Size textSizeNoWafer = getTextSize(textNoWafer, FONT_HERSHEY_SIMPLEX, 12NULL);
 
    while (true) {
        cap >> frame;
        if (frame.empty())
            break;
        
        cvtColor(frame, grayed, COLOR_BGR2GRAY);
        blur(grayed, blurred, Size(33));
        //GaussianBlur(grayed, blurred, Size(), 1.0);
        
        vector<Vec3f> circles;
        // void cv::HoughCircles(InputArray image, OutputArray circles, int method, double dp, double minDist, double param1 = 100, double param2 = 100, int minRadius = 0, int maxRadius = 0)
        // param1 - First method-specific parameter. In case of HOUGH_GRADIENT , it is the higher threshold of the two passed to the Canny edge detector (the lower one is twice smaller).
        // param2 - Second method - specific parameter.In case of HOUGH_GRADIENT, it is the accumulator threshold for the circle centers at the detection stage.The smaller it is, the more
        //            false circles may be detected.Circles, corresponding to the larger accumulator values, will be returned first.
        HoughCircles(blurred, circles, HOUGH_GRADIENT, 13001006050);
 
        if (circles.empty()) {
            putText(frame, textNoWafer, Point(cvRound(frameWidth / 2 - textSizeNoWafer.width / 2), cvRound(frameHeight / 2 + textSizeNoWafer.height / 2)), FONT_HERSHEY_SIMPLEX, 1, Scalar(00255), 2);
            imshow("frame", frame);
 
            if (waitKey(10== 27)
                break;
 
            continue;
        }
 
        for (Vec3f c : circles) {
            Point center(cvRound(c[0]), cvRound(c[1]));
            int radius = cvRound(c[2]);
 
            circle(frame, center, radius, Scalar(00255), 2);
            circle(frame, center, 2, Scalar(25500), 2);
            // void cv::putText(InputOutputArray img, const String & text, Point org, int fontFace, double fontScale, Scalar color, int thickness = 1, int lineType = LINE_8, bool bottomLeftOrigin = false)
            putText(frame, textWafer, Point2i(center.x - textSizeWafer.width / 2, center.y + textSizeWafer.height / 2), FONT_HERSHEY_SIMPLEX, 1, Scalar(02550), 2);
            //cout << "Wafer radius: " << radius << endl;
        }
 
        imshow("frame", frame);
 
        if (waitKey(10== 27)
            break;
    }
    
    return 0;
}












1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import cv2
 
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
 
frame_size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
print('frame_size =', frame_size)
 
text = 'Wafer detected'
textSize, baseLine = cv2.getTextSize(text, cv2.FONT_HERSHEY_SIMPLEX, 12)
 
while True:
    retval, frame = cap.read()
    if not retval:
        break
    blured = cv2.GaussianBlur(frame, ksize = (1515), sigmaX = 10.0)
    # Blurs an image using a Gaussian filter.
    grayed = cv2.cvtColor(blured,cv2.COLOR_BGR2GRAY)
    circles = cv2.HoughCircles(grayed, method = cv2.HOUGH_GRADIENT, dp = 1, minDist = 300,
                            param2 = 15, minRadius = 50)
    # Finds circles in a grayscale image using the Hough transform.
    if circles is None:
        cv2.imshow('Wafer detection', frame)
        key = cv2.waitKey(25)
        if key == 27# ESC
            break
        continue
 
    for circle in circles[0, :]:    
        cx, cy, r = circle
        cv2.circle(frame, (cx, cy), r, (00255), 2)    # Wafer
        cv2.circle(frame, (cx, cy), 2, (25500), 2)    # Center
 
        textX = int(cx - textSize[0/ 2)
        textY = int(cy + textSize[1/ 2)
        cv2.putText(frame, text, (textX, textY), cv2.FONT_HERSHEY_SIMPLEX, 1, (02550), 2)
        
    cv2.imshow('Wafer detection', frame)
 
    key = cv2.waitKey(25)
    if key == 27# ESC
        break
 
 
if cap.isOpened():
    cap.release()
cv2.destroyAllWindows()
cs


반응형

'OpenCV' 카테고리의 다른 글

OpenCV Graphic User Interface(GUI) with cvui  (0) 2019.07.01
How to extract video from a video file 영상 추출 하기  (0) 2019.06.29
Video Analysis - Optical Flow  (0) 2019.01.03
tkinter GUI  (0) 2018.12.29
Video Analysis - Meanshift and CAMshift  (0) 2018.12.27
Posted by J-sean
: