목록분류 전체보기 (295)
거의 알고리즘 일기장
In [6]: import torch import torch.nn as nn import torch.nn.functional as F from torch.utils.data import DataLoader import torchvision.datasets as datasets from torch.autograd import Variable import visdom import torch.optim as optim import torchvision.transforms as transforms In [7]: transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5,0.5,0.5), (0.5,0.5,0.5))]) train..
In [14]: import os import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable import torchvision from torch.utils.data import DataLoader, Dataset import PIL.Image as Image import matplotlib.pyplot as plt import torchvision.transforms as transforms import numpy as np In [15]: #custom trans = transforms.Compose([transforms.Resize((100, 100)), transforms...
1. 카메라, 동영상 열기 import sys import cv2 # 카메라 열기 #cap = cv2.VideoCapture() #cap.open(0) #위의 두줄과 같음 #cap = cv2.VideoCapture(0) #vidoe 열기 cap = cv2.VideoCapture("video1.mp4") if not cap.isOpened(): print("camera/video open failed!") sys.exit() #속성 받아오기 w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) print(w, h) #영상 출력 속성을 바꿀수도 있음, 지원이 안될경우 안바뀔수도 있으니 확인할것! cap.se..
import numpy as np import cv2 img = np.full((400, 400, 3), 255, np.uint8) cv2.line(img, (50,50), (200, 50), (0, 0, 255), 5) cv2.line(img, (50,60), (150, 160), (0, 0, 128)) cv2.rectangle(img, (50, 200, 150, 100), (0, 255, 0), 2) #thickness에 -1로 지정하면 내부를 채운다! cv2.rectangle(img, (70, 220), (180, 280), (0, 128, 0), -1) cv2.circle(img, (300, 100), 30, (255, 255, 0), -1, cv2.LINE_AA) cv2.circle(img, (..
ROI : Region Of Interest, 관심 영역, 영상에서 특정 연산을 수행하고자 하는 임의의 부분 영역 import sys import cv2 # # 마스크 영상을 이용한 영상 합성 # src = cv2.imread('airplane.bmp', cv2.IMREAD_COLOR) # mask = cv2.imread('mask_plane.bmp', cv2.IMREAD_GRAYSCALE) # dst = cv2.imread('field.bmp', cv2.IMREAD_COLOR) # # 방어코드 # if src is None or mask is None or dst is None: # print('Image load failed!') # sys.exit() # #사이즈가 같아야하고 src, dst는 타입..
In [3]: %matplotlib inline import matplotlib import matplotlib.pyplot as plt import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable from torch.utils.data import Dataset, DataLoader import numpy as np import torchvision import torchvision.transforms as transforms In [4]: transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0...
In [3]: %matplotlib inline import matplotlib import matplotlib.pyplot as plt import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable from torch.utils.data import Dataset, DataLoader import numpy as np import torchvision import torchvision.transforms as transforms In [4]: transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0...
In [10]: %matplotlib inline import matplotlib import matplotlib.pyplot as plt import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable from torch.utils.data import Dataset, DataLoader import numpy as np import torchvision import torchvision.transforms as transforms In [2]: transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0..
import numpy as np import cv2 # # 새 영상 생성하기 # img1 = np.empty((240, 320), dtype=np.uint8) # grayscale image # img2 = np.zeros((240, 320, 3), dtype=np.uint8) # color image # img3 = np.ones((240, 320), dtype=np.uint8) * 255 # dark gray # img4 = np.full((240, 320, 3), (0, 255, 255), dtype=np.uint8) # yellow # cv2.imshow('img1', img1) # cv2.imshow('img2', img2) # cv2.imshow('img3', img3) # cv2.imsho..
import sys import cv2 # 영상 불러오기 img1 = cv2.imread('cat.bmp', cv2.IMREAD_GRAYSCALE) img2 = cv2.imread('cat.bmp', cv2.IMREAD_COLOR) if img1 is None or img2 is None: print('Image load failed!') sys.exit() # 영상의 속성 참조 print('type(img1):', type(img1)) print('img1.shape:', img1.shape) print('img2.shape:', img2.shape) print('img1.dtype:', img1.dtype) # 영상의 크기 참조 # h, w 순서 h, w = img2.shape[:2] print('i..