영역 지정 (내가 헷갈려서 정리..)
사각형 그릴때나, x,y 좌표 지정할때나, mat 객체에 이미지 복사할때나 이거때문에 에러자꾸 나서 정리해야겠다. 1. numpy 배열 생성하기 bbp=3 : 컬러 bbp =1 : 그레이 2. shape 함수로 height, width, bbp 가져오기 순서대로 height, width, shape 3. 원하는 좌표에 도형 그리기 ex) 사각형 cv.rectangle(이미지 소스, (왼쪽 위 좌표),(오른쪽 아래 좌표), 색상, 굵기 ) 4. 이미지에서 특정 영역 가져오기 result = img[시작 y: 끝 y , 시작x, 끝 x] 출처: https://webnautes.tistory.com/580
이미지 기하학적 변환
1.단순 회전 cv.getRotationMatrix2D( (센터 좌표), 회전 각도, 이미지 크기 ) import cv2 as cv img = cv.imread('hamster.jpg') img_h, img_w = img.shape[:2] rotate = cv.getRotationMatrix2D((img_w/2, img_h/2), 45, 1) img_rotate = cv.warpAffine(img, rotate, (img_w, img_h)) cv.imshow("ass", img_rotate) cv.waitKey(0) 2. 크기 조정 cv.resize 사용 1) 확대 - 이미지 확대시에는 INTER_CUBIC, INTER_LINEAR 근데 CUBIC은 느리다 2) 축소 - 축소할때는 INTER_AREA 권..
ROI - 3 응용하기2 ( 평균 색 추출하기)
1. 사용 코드 1) Trackbar 2) mean 함수 - mat 행렬 원소의 평균 ※ cv.sum = 행렬 원소의 총합 import cv2 as cv import numpy as np def on_trackbar(x): pass cv.namedWindow('test') cv.createTrackbar('x', 'test', 0, 500, on_trackbar) cv.createTrackbar('y', 'test', 0, 500, on_trackbar) cv.setTrackbarPos('x', 'test', 150) cv.setTrackbarPos('y', 'test', 150) cap = cv.VideoCapture(0) while True: ret, img = cap.read() img_result..