def __init__(self, corner_a, corner_b, corner_c, corner_d): rng = cv.RNG() self.midx = rect_midpointx(corner_a, corner_b, corner_c, corner_d) self.midy = rect_midpointy(corner_a, corner_b, corner_c, corner_d) self.corner1 = corner_a self.corner2 = corner_b self.corner3 = corner_c self.corner4 = corner_d # locx and locy are relative locations of corners when compared to other corners of the same rectangle self.corner1_locx = self.corner1[0] - self.corner2[0] self.corner1_locy = self.corner1[1] - self.corner2[1] self.corner2_locx = self.corner2[0] - self.corner1[0] self.corner2_locy = self.corner2[1] - self.corner1[1] self.corner3_locx = self.corner3[0] - self.corner1[0] self.corner3_locy = self.corner3[1] - self.corner1[1] self.corner4_locx = self.corner4[0] - self.corner1[0] self.corner4_locy = self.corner4[1] - self.corner1[1] # angle is found according to short side if line_distance(corner_a, corner_c) < line_distance(corner_a, corner_b): self.angle = -angle_between_lines(line_slope(corner_a, corner_c), 0) else: self.angle = -angle_between_lines(line_slope(corner_a, corner_b), 0) self.id = 0 # id identifies which pizza your looking at self.last_seen = 2 # how recently you have seen this pizza self.seencount = 1 # how many times you have seen this pizza (if you see it enough it becomes confirmed) r = int(cv.RandReal(rng) * 255) g = int(cv.RandReal(rng) * 255) b = int(cv.RandReal(rng) * 255) self.debug_color = cv.RGB(r, g, b) self.object = random.choice(["A", "B", "C", "D"])
def addGaussianNoise(image_path, save_path): img = cv.LoadImage(image_path) noise = cv.CreateImage(cv.GetSize(img), img.depth, img.nChannels) cv.SetZero(noise) rng = cv.RNG(-1) cv.RandArr(rng, noise, cv.CV_RAND_NORMAL, cv.ScalarAll(0), cv.ScalarAll(25)) cv.Add(img, noise, img) tempName = os.path.splitext( os.path.basename(image_path))[0] + "_noised.jpg" save_image = os.path.join(save_path, tempName) cv.SaveImage(save_image, img)
def init(self): # Thresholds self.minsize = 50 self.maxsize = 300 # List we store found buoys in self.new = [] if self.debug: # windows #cv.NamedWindow("Buoy" + self.camera_name) # random number generator used for choosing debug colors self.rng = cv.RNG()
def init(self): # Total Number of Buoys Found self.buoy_count = 0 # Average disparity across cameras self.avg_disparity = 0 # Buoy Classes self.newLeft = [] self.newRight = [] self.candidates = [] self.confirmed = [] self.lost = [] if self.debug: # random number generator used for choosing debug colors self.rng = cv.RNG()
def noisy(image, noise_typ, filename): if noise_typ == "gauss": row, col = image.shape mean = 0 deviation = 30 #var = 0.1 #sigma = var**0.5 gauss = np.random.normal(mean, deviation, (row, col)) gauss = gauss.reshape(row, col) noisy = image + gauss misc.imsave(filename, noisy) elif noise_typ == "s&p": row, col = image.shape s_vs_p = 0.5 amount = 0.01 out = image # Salt mode num_salt = np.ceil(amount * image.size * s_vs_p) coords = [ np.random.randint(0, i - 1, int(num_salt)) for i in image.shape ] out[coords] = 255 # Pepper mode num_pepper = np.ceil(amount * image.size * (1. - s_vs_p)) coords = [ np.random.randint(0, i - 1, int(num_pepper)) for i in image.shape ] out[coords] = 0 misc.imsave(filename, out) elif noise_typ == "speckle": mult_noise = cv.CreateImage((image.width, image.height), cv.IPL_DEPTH_32F, 1) cv.RandArr(cv.RNG(6), mult_noise, cv.CV_RAND_NORMAL, 1, 0.1) cv.Mul(image, mult_noise, image) cv.SaveImage(filename, image) elif noise_typ == "blur": blur = ndimage.gaussian_filter(image, sigma=3) misc.imsave(filename, blur)
def init(self): # Total Number of Buoys Found self.buoy_count = 0 # Thresholds self.minsize = 20 self.maxsize = 40 # Buoy Classes self.new = [] self.candidates = [] self.confirmed = [] self.lost = [] #self.debug = True if self.debug: # windows # cv.NamedWindow("BuoyTest") # random number generator used for choosing debug colors self.rng = cv.RNG()
Pressing ESC will stop the program. """ import urllib2 import cv from math import cos, sin, sqrt import sys if __name__ == "__main__": A = [[1, 1], [0, 1]] img = cv.CreateImage((500, 500), 8, 3) kalman = cv.CreateKalman(2, 1, 0) state = cv.CreateMat(2, 1, cv.CV_32FC1) # (phi, delta_phi) process_noise = cv.CreateMat(2, 1, cv.CV_32FC1) measurement = cv.CreateMat(1, 1, cv.CV_32FC1) rng = cv.RNG(-1) code = -1L cv.Zero(measurement) cv.NamedWindow("Kalman", 1) while True: cv.RandArr(rng, state, cv.CV_RAND_NORMAL, cv.RealScalar(0), cv.RealScalar(0.1)) kalman.transition_matrix[0, 0] = 1 kalman.transition_matrix[0, 1] = 1 kalman.transition_matrix[1, 0] = 0 kalman.transition_matrix[1, 1] = 1 cv.SetIdentity(kalman.measurement_matrix, cv.RealScalar(1))
import cv im = cv.LoadImage('melon.jpg', cv.CV_LOAD_IMAGE_GRAYSCALE) mult_noise = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_32F, 1) cv.RandArr(cv.RNG(6), mult_noise, cv.CV_RAND_NORMAL, 1, 0.1) cv.Mul(im, mult_noise, im) cv.ShowImage("tree with speckle noise", im) cv.WaitKey(0)