前提
教えてください!
実現したいこと
問題・課題
。
できようにしたい。
ソース付きで教えてくれると幸いです。
該当のソースコード
Python
ソースコード
import cv2 import os def save_frame_camera_key(device_num, dir_path, basename, ext='jpg', delay=1, window_name='frame'): cap = cv2.VideoCapture(device_num) if not cap.isOpened(): return os.makedirs(dir_path, exist_ok=True) base_path = os.path.join(dir_path, basename) n = 0 while True: ret, frame = cap.read() cv2.imshow(window_name, frame) key = cv2.waitKey(delay) & 0xFF if key == ord('c'): cv2.imwrite('{}_{}.{}'.format(base_path, n, ext), frame) n += 1 elif key == ord('q'): break cv2.destroyWindow(window_name) #画像のサイズ縮小 height = image.shape[0] width = image.shape[1] image = cv2.resize(image,(round(width/4), round(height/4))) image_copy1 = image.copy() #グレースケール化 image_copy1 = cv2.cvtColor(image_copy1,cv2.COLOR_BGR2GRAY) #閾値処理 ret,thresh = cv2.threshold(image_copy1,128,255,cv2.THRESH_BINARY) #輪郭検出 (cv2.ChAIN_APPROX_SIMPLE) contours1, hierarchy1 = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) #輪郭の描画 cv2.drawContours(image, contours1, -1, (0, 255, 0), 2, cv2.LINE_AA) #実行結果 cv2.imshow('Drawn contours', image) cv2.imshow('Original', image_copy1) cv2.waitKey(0) cv2.destroyAllWindows() save_frame_camera_key(0, 'syasin', 'IMG_RINKAKU')

回答1件
あなたの回答
tips
プレビュー