qr코드 인식 : http://blog.daum.net/pg365/186


1. 그레이로 변경

        image = cv2.imread("sample.jpg", cv2.IMREAD_COLOR)

        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)


        hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

2. 이미지 저장

cv2.imwrite('image.jpg', image)

3. 블랙 화이트 분리

ret,thresh1 = cv2.threshold(gray,127,255,cv2.THRESH_BINARY)


4. 화이트 색상 HSV 값

http://stackoverflow.com/questions/22588146/tracking-white-color-using-python-opencv


sensitivity = 15
lower_white = np.array([0,0,255-sensitivity])
upper_white = np.array([255,sensitivity,255])

5. 색상 반전

imagem = cv2.bitwise_not(imagem)


6. 카메라 해상도 변경

cap = cv2.VideoCapture(0)

cap.set(3, 1280.)
cap.set(4, 720.)


7. 외곽선 추출

python

http://www.pyimagesearch.com/2014/04/21/building-pokedex-python-finding-game-boy-screen-step-4-6/


        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

        gray = cv2.bilateralFilter(gray, 11, 17, 17)

        edged = cv2.Canny(gray, 30, 200)


        cnts = cv2.findContours(edged.copy(), cv2.RETR_TREE,

                cv2.CHAIN_APPROX_SIMPLE)[-2]


cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:10]

            

            screenCnt = None


            


            

            print 'start'

            for cnt in cnts:

                epsilon = 0.1 * cv2.arcLength(cnt, True)

                polygon = cv2.approxPolyDP(cnt, epsilon, True)


                if len(polygon) == 4:

                #if True:

                    screenCnt = polygon

                    #cv2.drawContours(temp, [screenCnt], -1, (0, 255, 0), 3)

                    cv2.drawContours(image, [screenCnt], -1, (0, 255, 0), 3)

                    #cv2.imshow("Screen", temp)

                    print 'find!!'

                    break

            print 'end' 

c

===========아래===========

http://hongkwan.blogspot.kr/2013/01/opencv-7-4-example.html

cv::findContours(image, 
contours, // 외곽선 벡터 
CV_RETR_EXTERNAL, // 외부 외곽선 검색
CV_CHAIN_APPROX_NONE); // 각 외곽선의 모든 화소 탐색
// 지정된 플래그 - 첫 번째는 외부 외곽선이 필요함을 나타내며 객체의 구멍을 무시
// 두 번째 플래그는 외곽선의 형태를 지정 - 현재 옵션으로 벡터는 외곽선 내의 모든 화소 목록
// CV_CHAIN_APPROX_SIMPLE 플래그로 하면 마지막 점이 수평 또는 수직, 대각선 외곽선에 포함됨
// 다른 플래그는 간결한 표현을 얻기 위해 외곽선의 정교하게 연결된 근사치를 제공

// 이전 영상으로 9개 외곽선을 contours.size()로 얻음
// drawContours() 함수는 영상 내의 각 외곽선을 그릴 수 있는 함수
// 하얀 영상 내 검은 외곽선 그리기
cv::Mat result(image.size(), CV_8U, cv::Scalar(255));
cv::drawContours(result, contours,
-1, // 모든 외곽선 그리기
cv::Scalar(0), // 검게
2); // 두께를 2로
// 세 번째 파라미터가 음수라면 모든 외곽선이 그려짐
// 반면 그려져야 하는 외곽선의 첨자를 지정할 수 있음

8. 


'영상처리 > OpenCV' 카테고리의 다른 글

OpenCV - Diffence Image 영상차  (0) 2017.01.04
Posted by 공놀이나하여보세
,