Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 공부
- Windows10
- OpenCV
- 텐서플로우
- c
- shell
- 리눅스
- 시스템프로그래밍
- CV
- 백준
- TensorFlow
- 학습
- Computer Vision
- 코딩
- C언어
- 턱걸이
- C++
- error
- python
- 운영체제
- linux
- 회귀
- Windows 10
- 백준알고리즘
- 알고리즘
- 쉘
- 영상처리
- 프로세스
- 프로그래밍
- 딥러닝
Archives
- Today
- Total
줘이리의 인생적기
CV - opencv(Python) 비디오에 라인, 원, 사각형 그리기 본문
728x90
영상에 라인을 그려보도록 하겠습니다.
주차 시 후방 카메라에서 많이 보셨을 겁니다.
차선과 평행 방향으로 라인 그리기
라인, 원, 사각형 삽입 코드 원형 설명
#라인 그리기
def drawLine(image, point1, point2, color=(255, 0, 0), thickness=3, lineType=cv2.LINE_AA):
result = imageCopy(image)
return cv2.line(result, point1, point2, color, thickness, lineType)
#원 그리기
def drawCircle(image, center, radius, color=(255, 0, 0), thickness=3, lineType=cv2.LINE_AA):
result = imageCopy(image)
return cv2.circle(result, center, radius, color, thickness, lineType)
#사각형 그리기
def drawRect(image, point1, point2, color=(255, 0, 0), thickness=3, lineType=cv2.LINE_AA):
result = imageCopy(image)
return cv2.rectangle(result, point1, point2, color, thickness, lineType)
전체 코드
더보기
# -*- coding: utf-8 -*-
from OpenCV_Functions import *
def imageProcessing2(image):
result = imageCopy(image)
pt1 = (430, 310)
pt2 = (530, 310)
pt3 = (940, 540)
pt4 = (20, 540)
result = drawLine(result, pt1, pt2, (255, 0, 0), 5)
result = drawLine(result, pt2, pt3, (255, 0, 0), 5)
result = drawLine(result, pt3, pt4, (255, 0, 0), 5)
result = drawLine(result, pt4, pt1, (255, 0, 0), 5)
height = image.shape[0]
width = image.shape[1]
pt1 = (int(width * 0.5), int(height * 0.5))
pt2 = (int(width), int(height))
pt3 = (0, height)
result = drawLine(result, pt1, pt2, (0, 255, 0), 5)
result = drawLine(result, pt2, pt3, (0, 255, 0), 5)
result = drawLine(result, pt3, pt1, (0, 255, 0), 5)
pt1 = (0,0)
pt2 = (width, height)
result = drawRect(result, pt1, pt2, (0, 0, 0), 5)
pt1 = (int(width * 0.5), int(height * 0.5))
result = drawCircle(result, pt1, 3, (255, 255, 255), -1)
return result
def Video2(openpath, savepath = "output.avi"):
cap = cv2.VideoCapture(openpath)
if cap.isOpened():
print("Video Opened")
else:
print("Video Not Opened")
print("Program Abort")
exit()
fps = cap.get(cv2.CAP_PROP_FPS)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fourcc = int(cap.get(cv2.CAP_PROP_FOURCC))
out = cv2.VideoWriter(savepath, fourcc, fps, (width, height), True)
cv2.namedWindow("Input", cv2.WINDOW_GUI_EXPANDED)
cv2.namedWindow("Output", cv2.WINDOW_GUI_EXPANDED)
import OpenCV_Functions
while cap.isOpened():
ret, frame = cap.read()
if ret:
output = imageProcessing2(frame)
out.write(output)
cv2.imshow("Input", frame)
cv2.imshow("Output", output)
else:
break
if cv2.waitKey(int(1000.0/fps)) & 0xFF == ord('q'):
break
cap.release()
out.release()
cv2.destroyAllWindows()
return
road_video_01 = "<비디오 경로>"
Video2(road_video_01, "output.mp4")
'공부 > Computer Vision(py)' 카테고리의 다른 글
CV - opencv(Python) Blur, GaussianBlur, MedianBlur (0) | 2020.07.17 |
---|---|
CV - opencv(Python) addImage, addWeightedImage, imageThreshold (0) | 2020.07.16 |
CV - opencv(Python) White, Yellow 차선 검출 (0) | 2020.07.10 |
CV - opencv(Python) ROI, Channels (0) | 2020.07.09 |
CV - opencv(Python) 이미지 열기, 창 띄우기, 픽셀 접근 (0) | 2020.07.08 |