본문 바로가기

수업(국비지원)371

[Python] 2개의 이미지 호출, 이미지에서 얼굴, 눈 표시하기 📌 # bitwise 함수 : 2개의 이미지 호출하기 import numpy as np, cv2 image1 = np.zeros((300, 300), np.uint8) # 300행, 300열 검은색 영상 생성 image2 = image1.copy() image1.shape cv2.imshow("image1", image1) cv2.imshow("image2", image2) h, w = image1.shape[:2] print(h, w) cx, cy = w//2, h//2 print(cx, cy) cv2.circle(image1, (cx, cy), 100, 255, -1) # 중심에 원 그리기 cv2.rectangle(image2, (0, 0, cx, h), 255, -1) image3 = cv2.bit.. 2023. 4. 27.
[Python] 웹 숫자 예측 프로그램 만들기 환경설정 장고 설정하기 📌 settings.py - study1 내용 추가 """ Django settings for study1 project. Generated by 'django-admin startproject' using Django 4.1.4. For more information on this file, see For the full list of settings and their values, see """ from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent # Quick-start development.. 2023. 4. 27.
[Python] 실제 숫자 이미지 처리하기 📌 # 이미지 파일을 읽어서 학습하기 import numpy as np, cv2 import matplotlib.pyplot as plt size = (40, 40) # 튜플. 이미지 한개의 크기 nclass, nsample = 10, 20 train_image = cv2.imread('images/train_numbers.png', cv2.IMREAD_GRAYSCALE) train_image.shape train_image = train_image[5:405, 6:806] # 이미지의 여백들을 제거. train_image.shape # threshold : 이미지의 값을 명확한 값으로 정리.(이미지 전처리) # cv2.threshold(train_image, 32, 255, cv2.THRESH_BINA.. 2023. 4. 27.
[Python] 2022-12-27 복습 📌 # 알고리즘 학습 knn = cv2.ml.KNearest_create() # knn알고리즘. # 훈련하기 # train_data : 훈련데이터. 50000개 # cv2.ml.ROW_SAMPLE : 행값이 데이터. 1개 행이 학습 데이터 1개 # train_label : 정답 knn.train(train_data, cv2.ml.ROW_SAMPLE, train_label) # 예측하기 # test_data[:100] : 100개만 예측하기 # k=5 : knn 알고리즘은 근접한 5개의 점을 선택. _, resp, _, _ = knn.findNearest(test_data[:100], k=5) # resp.flatten() : 1차원 배열의 값으로 변형. [[값]] accur = sum(test_label.. 2023. 4. 27.
[Python] 숫자 인식하기 📌 # 손글씨 예측 import cv2 import numpy as np import pickle, gzip, os from urllib.request import urlretrieve import matplotlib.pyplot as plt def load_mnist(filename) : if not os.path.exists(filename) : # 존재하지 않으면 link = \\ "" urlretrieve(link, filename) # Link에서 전달한 파일을 filename으로 저장 with gzip.open(filename,"rb") as f: # 압축파일을 읽기 return pickle.load(f, encoding="latin1") train_set, valid_set, test_set.. 2023. 4. 27.
[Python] 동영상 파일 저장, 출력, 저장된 동영상 이미지 색상 수정 📌 ##### 동영상을 파일로 저장하기 import cv2 capture = cv2.VideoCapture(0) # 카메라 객체 연결 if capture.isOpened() == False : raise Exception("카메라 연결 안됨") fps = 20.0 # 카메라의 초당 프레임의 수. delay = round(1000/fps) size = (640,480) # *"DX50" : 코덱 종류 설정. (* : 포인터 변수.) fourcc = cv2.VideoWriter_fourcc(*"DX50") #코덱설정 print("프레임 해상도: ", size) print("압축코덱숫자: ", fourcc) print("delay: %2d ms" % delay) print("fps: %.2f" % fps) #.. 2023. 4. 27.
[Python] 동영상 파일 출력 📌 ###### 동영상 파일 import cv2 capture = cv2.VideoCapture(0) # 카메라 객체 연결 if capture.isOpened() == False : raise Exception("카메라 연결 안됨") # 카메라 속성값 print("너비 %d" % capture.get(cv2.CAP_PROP_FRAME_WIDTH)) # 가로 길이 print("높이 %d" % capture.get(cv2.CAP_PROP_FRAME_HEIGHT)) # 세로 길이 print("노출 %d" % capture.get(cv2.CAP_PROP_EXPOSURE)) print("밝기 %d" % capture.get(cv2.CAP_PROP_BRIGHTNESS)) # 동영상에 지정된 위치에 문자 출력하는 함.. 2023. 4. 27.
[Python] 이미지 형태 분석 📌 import cv2 # 이미지 형태 분석 def print_matInfo(name, image) : #image : 이미지를 읽은 배열값.(이미지 데이터 값.) # image.dtype : 배열요소의 자료형. if image.dtype == 'uint8' : mat_type = "CV_8U" # 부호가 없는 8비트(0~225). 기본적인 지정방식. elif image.dtype == 'int8' : mat_type = "CV_8S" # 부호가 있는 8비트(-128~127). 자바에서는 byte타입 elif image.dtype == 'uint16' : mat_type = "CV_16U" # 부호가 없는 16비트 elif image.dtype == 'int16' : mat_type = "CV_16S" .. 2023. 4. 27.