FANDOM


Here are the notes from 2/01 on using OpenCV. Probably not 100% accurate, feel free to edit them as you see. This is in python. This probably wouldn't compile.

import numpy

import cv2
img=cv2.imread('~/hyrule.jpg',0)
img[100,200]=[255,255,255] #Modifying single pixel
img[100,200,1]=255 #Or to modify just one color of the pixel, simply assign to a single value

shp=img.shape #returns a TUPLE (similar to a list) with the rows, colmns, and number of channels (#of colors (3 for RGB), no return if grayscale)

sz=img.size #returns number of pixels

dtype = img.dtype #returns datatype of the image, uint8 (unsigned 8 bit integer)

#Region of Interest - cropped section of an image
#Searching a smaller area for an object when tracking - Start big, then get smaller (person in crowd->person->face->eye->veins)

region = img[123:234, 112:233] #Note the range, it cannot exceed pixels in image

#region is a new image! You can save this image

img [123:234, 112:233]=region #assign image back to original (e.g. cut out soccer ball, modify ball, paste it back to image)
#image range must be identical in size to picture being assigned

b,g,r=cv2.split(img) #returns 3 matrices (2d), b=blue channel, g=green, r=red ORDER MATTERS HERE!!!!!!!! bgr order not rgb

b=img[:,:,0] #0 gets color channel, : is all values

img=cv2.merge((b,g,r)) #merging rgb backing to original
img[:,:,0]=255 #set every blue channel to max
img[:,:,0:1]=255 #sets blue and green to max

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.