ㅇ VNC 원격 테스트
ㅇ 자동차 CCTV 환경
ㅇ 주행 테스트 환경
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()
'1. SW 개발 & IT 트렌드' 카테고리의 다른 글
로봇 플랫폼 - Zippy the Raspberry Pi Zero-powered mini Mars Rover (0) | 2021.09.12 |
---|---|
디비털 팝아트? Raspberry Pi displays album art on LED matrix (0) | 2021.09.08 |
초보자를 위한 Get started with Raspberry Pi - raspberrypi.org (0) | 2021.09.01 |
IoT 플랫폼 기반 - 원격제어 자동차 조립 (0) | 2021.08.31 |
PWM(Pulse Width Modulation) : 라즈베리파이 (0) | 2021.08.31 |
댓글