본문 바로가기
1. SW 개발 & IT 트렌드

[테스트] 자율주행 자동차 테스트 환경

by soosun 2021. 9. 4.

ㅇ VNC 원격 테스트

 

ㅇ 자동차 CCTV 환경 

 

ㅇ 주행 테스트 환경

1. 책에서 사용한 트랙
2. 1차 테스트 용 트랙
2. 좀더 확장한 테스트 트랙

 

o Open CV : Eroding and Dilating 

https://docs.opencv.org/3.4/db/df6/tutorial_erosion_dilatation.html

 

  • Apply two very common morphological operators: Erosion and Dilation. For this purpose, you will use the following OpenCV functions:

- Base

- Dilation

The dilatation operation is: dst(x,y)=max(x,y): element(x,y)0 src(x+x,y+y)

- Erosion

The erosion operation is: dst(x,y)=min(x,y): element(x,y)0 src(x+x,y+y)

o moments 

moments 객체의 무게중심 및 면적 등의 특성을 계산할때 유용
- 공간, 중심, 평준화된 중심 

https://docs.opencv.org/3.4/d0/d49/tutorial_moments.html

 

 

o What are contours?

https://docs.opencv.org/4.5.0/d4/d73/tutorial_py_contours_begin.html

- Test Code 

import cv2
import numpy as np

def main():
    camera = cv2.VideoCapture(0)
    camera.set(3, 160) 
    camera.set(4, 120)

    while( camera.isOpened() ):
        ret, frame = camera.read()
        frame = cv2.flip(frame, -1)
        cv2.imshow('normal', frame)
        
        crop_img =frame[60:120, 0:160]
        
        gray = cv2.cvtColor(crop_img, cv2.COLOR_BGR2GRAY)
    
        blur = cv2.GaussianBlur(gray, (5,5), 0)
        
        ret,thresh1 = cv2.threshold(blur, 130, 255, cv2.THRESH_BINARY_INV)
        
        mask = cv2.erode(thresh1, None, iterations=2)
        mask = cv2.dilate(mask, None, iterations=2)
        cv2.imshow('mask', mask)
    
        contours,hierarchy = cv2.findContours(mask.copy(), 1, cv2.CHAIN_APPROX_NONE)
        
        if len(contours) > 0:
            c = max(contours, key=cv2.contourArea)
            M = cv2.moments(c)
            
            cx = int(M['m10'] / M['m00'])
            cy = int(M['m01'] / M['m00'])
            
            cv2.line(crop_img, (cx,0), (cx,720), (255,0,0), 1)
            cv2.line(crop_img, (0,cy), (1280,cy), (255,0,0), 1)
        
            cv2.drawContours(crop_img, contours, -1, (0,255,0), 1)
            
            print(cx)
        
        if cv2.waitKey(1) == ord('q'):
            break
    
    cv2.destroyAllWindows()

if __name__ == '__main__':
    main()

 

댓글