OpenCV-Python 基本的な操作
基本的な操作を色々試してみた
import numpy as np import cv2 import datetime import math img = cv2.imread("dsub.jpg") maxX = img.shape[0] maxY = img.shape[1] colorNo = img.shape[2] dataSize = img.size dataType = img.dtype print("MaxX:" + str(maxX) + " MaxY:" + str(maxY) + " Color:" + str(colorNo) + " Size:" + str(dataSize) + " Data Type:" + str(dataType)) print(len(img[0])) #=480 print(len(img)) #640 # #[[480],[480],...,[480]] #<------ 640-----------> # #[0,0,0]=black #[255,255,255] = white #[255,0,0] = blue #[0,255,0] = green #[0,0,255] = red #コピーは参照渡しになる #img2.item(x,y,0) 読み出し 3項目は色 #img2.itemset((x,y,0),value) 書込み img2 = img for x in range(int(maxX/2)): for y in range(int(maxY/2)): #img2[x,y] = [x % 256,y % 256,x % 256] #img2.itemset((x,y,0),img2.item(x,y,0) /5) img2.itemset((x,y,0),math.sqrt(x*x+y*y) % 256) #画像中の注目領域(ROI) ball = img[280:340, 330:390] img[273:333, 100:160] = ball #色の分解 b,g,r = cv2.split(img) #print(b) cv2.imshow('image_b',b) cv2.waitKey(0) #cv2.imshow('image_g',g) #cv2.waitKey(0) #cv2.imshow('image_r',r) #cv2.waitKey(0) #色の結合 img = cv2.merge((b,g,r)) #色の取り出し2(Numpyインデックス) b = img[:,:,0] #色の変更(Numpyインデックス) img[:,:,0] = 0 img[:,:,1] = 0 cv2.imshow('image',img) cv2.waitKey(0) cv2.destroyAllWindows() #for i in img[maxX-1]: # print(i) #cv2.imshow('image',img) #cv2.waitKey(0) #cv2.destroyAllWindows()
コメント
コメントを投稿