src = cv2.imread("test.jpg", cv2.IMREAD_COLOR)
if src is None:
print("Image load failed!")
exit(1)
cv2.imwrite('dst.jpg', src)
cv2.namedWindow("src")
cv2.imshow("src", src)
cv2.destroyAllWindows()
if cv2.waitkey(2) == 27:
break
dst = cv2.cvtColor(src,cv2.COLOR_BGR2GRAY)
dst = cv2.hconcat([src, src_gray])
dst = cv2.vconcat([src, src_gray])
카메라 연결: cap = cv2.VideoCapture(0)
or cap = cv2.VideoCapture("output.avi")
카메라 or 동영상 연결 확인
if cap.isOpened() == False:
print("Camera open failed!")
exit(1)
카메라에서 영상 불러오기: ret, frame = cap.read()
영상 불러오기 확인
if ret == False:
print("Image load failed!")
break
속성 얻어오기
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
width = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
fps = cap.get(cv2.CAP_PROP_FPS)
delay = round(1000 / fps)
카메라 연결 해제: cap.release()
src.dtype
: unit8
src.shape
:
src.size
:
dst1 = src.copy()
dsr2 = np.zeros((height, width), np.uint8)
dst1 = src
dst2 = src[y : y + height + 1, x : x + width + 1]
ㅜ
dst2 = cv2.copyTo(src, mask)
height, width = src.shape[:2]
for y in range(0, height):
for x in range(0, width):
b, g, r = src.item(y, x , 0), src.item(y, x , 1), src.item(y, x , 2)
src.itemset(y, x, 0, 124)
planes = cv2.split(src)
dst = merge(planes)
def on_trackbar(x):
pass
...
while cv2.waitKey(1) != 27:
low = cv2.getTrackbarPos("low_threshold", "src")
high = cv2.getTrackbarPos("high_threshold", "src")
canny = cv2.Canny(src, low, high)
cv2.imshow("src", canny)
cv2.lune(src, (x1, y1), (x2, y2), (0, 0, 255), 1)
cv2.rectangle(src, (x1, y1), (x2, y2), (0, 0, 255), 2)
cv2.rectangle(src, (x1, y1), (x2, y2), (0, 0, 255), -1)
cv2.rectangle(src, (x, y, width, height), (0, 0, 255), -2)
cv2.circle(src, (x, y), radius, (0, 0, 255), 1)
pts = np.array([[x1, y1], [x2, y2], [x3, y3]], np.int32)
cv2.polylines(img, [pts], True,(0, 0, 255), 2)
cv2.fillPoly(img, [pts], (0, 0, 255))
cv2.putText(src, text, (30, 30), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255), 2)
tm = cv2.TickMeter()
tm.start()
tm.stop()
ms = tm.getTimeMilli()
cv2.copyTo(src, mask, dst)
roi = src[y : y + height, x : x + width]
mask = np.zeros((height, width), np.uint8)
cv2.fillPoly(mask, [pts], (255))
dst = cv2.copyTo(src, mask)
blur1 = cv2.GaussianBlur(src, (3, 3), 0)
blur2 = cv2.GaussianBlur(src, (5, 5), 0)
canny = cv2.Canny(np.uint8(blur), low_threshold, high_threshold)
canny = cv2.Canny(blur, low_threshold, high_threshold)
hsv = cv2.cvtColor(src, cv2.COLOR_BGR2HSV)
low = np.array([0, 0, 70])
high = np.array([131, 255, 255]) # np.array([131, 255, 255], dtype=np.uint8)
mask = cv2.inRange(hsv, low, high)