Best Python code snippet using fMBT_python
createAquarium.py
Source:createAquarium.py
1# coding=utf-82"""3Sebastián Salinas, CC3501-Tarea3a 4Creating the aquarium via scene graph5"""6import numpy as np7import transformations as tr8import basic_shapes as bs9import scene_graph as sg10import easy_shaders as es11class aquarium():12 def __init__(self):13 self.posX = 0 # Posición en la manada en el eje X14 self.posY = 0 # Posición en la manada en el eje Y15 self.posZ = 0 # Posición en la manada en el eje Z16 self.localizacion = [0,0,0] # Localización en el mundo 3D17 def createAquariumEdges(self,x,y,z):18 # Basic GPUshapes 19 self.gpuBlackCube = es.toGPUShape(bs.createColorNormalsCube(0,0,0)) 20 # Fierro base21 self.fierro = sg.SceneGraphNode("fierro")22 self.fierro.transform = tr.scale(1,1,1) 23 self.fierro.childs += [self.gpuBlackCube]24 # Creating 3 types of edges25 self.fierroX = sg.SceneGraphNode("fierroX")26 self.fierroX.transform = tr.scale(x,0.05,0.05)27 self.fierroX.childs += [self.fierro]28 self.fierroY = sg.SceneGraphNode("fierroY")29 self.fierroY.transform = tr.scale(0.05,y,0.05)30 self.fierroY.childs += [self.fierro]31 self.fierroZ = sg.SceneGraphNode("fierroZ")32 self.fierroZ.transform = tr.scale(0.05,0.05,z)33 self.fierroZ.childs += [self.fierro]34 35 # Creating the edges of the aquarium36 self.fierroX_1 = sg.SceneGraphNode("fierroX_1")37 self.fierroX_1.transform = tr.translate(0,0,0) 38 self.fierroX_1.childs += [self.fierroX]39 self.fierroX_2 = sg.SceneGraphNode("fierroX_2")40 self.fierroX_2.transform = tr.translate(0,-y,0) 41 self.fierroX_2.childs += [self.fierroX]42 self.fierroX_3 = sg.SceneGraphNode("fierroX_3")43 self.fierroX_3.transform = tr.translate(0,0,z) 44 self.fierroX_3.childs += [self.fierroX]45 self.fierroX_4 = sg.SceneGraphNode("fierroX_4")46 self.fierroX_4.transform = tr.translate(0,-y,z) 47 self.fierroX_4.childs += [self.fierroX]48 self.fierroY_1 = sg.SceneGraphNode("fierroY_1")49 self.fierroY_1.transform = tr.translate(-x/2,-y/2,0) 50 self.fierroY_1.childs += [self.fierroY]51 self.fierroY_2 = sg.SceneGraphNode("fierroY_2")52 self.fierroY_2.transform = tr.translate(x/2,-y/2,0) 53 self.fierroY_2.childs += [self.fierroY]54 self.fierroY_3 = sg.SceneGraphNode("fierroY_3")55 self.fierroY_3.transform = tr.translate(-x/2,-y/2,z) 56 self.fierroY_3.childs += [self.fierroY]57 self.fierroY_4 = sg.SceneGraphNode("fierroY_4")58 self.fierroY_4.transform = tr.translate(x/2,-y/2,z)59 self.fierroY_4.childs += [self.fierroY]60 self.fierroZ_1 = sg.SceneGraphNode("fierroZ_1")61 self.fierroZ_1.transform = tr.translate(-x/2,0,z/2) 62 self.fierroZ_1.childs += [self.fierroZ]63 self.fierroZ_2 = sg.SceneGraphNode("fierroZ_2")64 self.fierroZ_2.transform = tr.translate(x/2,0,z/2) 65 self.fierroZ_2.childs += [self.fierroZ]66 self.fierroZ_3 = sg.SceneGraphNode("fierroZ_3")67 self.fierroZ_3.transform = tr.translate(-x/2,-y,z/2) 68 self.fierroZ_3.childs += [self.fierroZ]69 self.fierroZ_4 = sg.SceneGraphNode("fierroZ_4")70 self.fierroZ_4.transform = tr.translate(x/2,-y,z/2) 71 self.fierroZ_4.childs += [self.fierroZ]72 # Juntar los edges en 3 tipos de marcos73 self.marcoX = sg.SceneGraphNode("marcoX")74 self.marcoX.transform = tr.identity() 75 self.marcoX.childs += [self.fierroX_1, self.fierroX_2, self.fierroX_3, self.fierroX_4]76 self.marcoY = sg.SceneGraphNode("marcoY")77 self.marcoY.transform = tr.identity() 78 self.marcoY.childs += [self.fierroY_1, self.fierroY_2, self.fierroY_3, self.fierroY_4]79 self.marcoZ = sg.SceneGraphNode("marcoZ")80 self.marcoZ.transform = tr.identity()81 self.marcoZ.childs += [self.fierroZ_1, self.fierroZ_2, self.fierroZ_3, self.fierroZ_4]82 # Creating the aquarium83 self.aquarium = sg.SceneGraphNode("aquarium")84 self.aquarium.transform = tr.identity() #tr.matmul([tr.translate(0,y/4,0),tr.scale(0.5,0.5,0.5)])85 self.aquarium.childs += [self.marcoX, self.marcoY, self.marcoZ]86 return self.aquarium87 def createAquariumWindows(self,x,y,z):88 # Basic GPUshapes 89 self.gpuCyanCube = es.toGPUShape(bs.createColorCube(0,206/255,209/255)) # darkturquoise rgb(0,206,209) -> (0,206/255,209/255)90 # ventana base91 self.window = sg.SceneGraphNode("window")92 self.window.transform = tr.scale(1,1,1) 93 self.window.childs += [self.gpuCyanCube]94 # Creating 3 types of windows95 self.windowXY = sg.SceneGraphNode("windowXY")96 self.windowXY.transform = tr.scale(x,y,0.05)97 self.windowXY.childs += [self.window]98 self.windowXZ = sg.SceneGraphNode("windowXZ")99 self.windowXZ.transform = tr.scale(x,0.05,z)100 self.windowXZ.childs += [self.window]101 self.windowYZ = sg.SceneGraphNode("windowYZ")102 self.windowYZ.transform = tr.scale(0.05,y,z)103 self.windowYZ.childs += [self.window]104 # Creating the windows of the aquarium105 self.windowXY_1 = sg.SceneGraphNode("windowXY_1")106 self.windowXY_1.transform = tr.translate(0,-y/2,0) 107 self.windowXY_1.childs += [self.windowXY]108 self.windowXY_2 = sg.SceneGraphNode("windowXY_2")109 self.windowXY_2.transform = tr.translate(0,-y/2,z) 110 self.windowXY_2.childs += [self.windowXY]111 self.windowXZ_1 = sg.SceneGraphNode("windowXZ_1")112 self.windowXZ_1.transform = tr.translate(0,0,z/2) 113 self.windowXZ_1.childs += [self.windowXZ]114 self.windowXZ_2 = sg.SceneGraphNode("windowXZ_2")115 self.windowXZ_2.transform = tr.translate(0,-y,z/2) 116 self.windowXZ_2.childs += [self.windowXZ]117 self.windowYZ_1 = sg.SceneGraphNode("windowYZ_1")118 self.windowYZ_1.transform = tr.translate(-x/2,-y/2,z/2) 119 self.windowYZ_1.childs += [self.windowYZ]120 self.windowYZ_2 = sg.SceneGraphNode("windowYZ_2")121 self.windowYZ_2.transform = tr.translate(x/2,-y/2,z/2) 122 self.windowYZ_2.childs += [self.windowYZ]123 # Creating the aquarium124 self.aquarium = sg.SceneGraphNode("aquarium")125 self.aquarium.transform = tr.identity() #tr.matmul([tr.translate(0,y/4,0),tr.scale(0.5,0.5,0.5)]) 126 self.aquarium.childs += [self.windowXY_1, self.windowXY_2,self.windowXZ_1, self.windowXZ_2, self.windowYZ_1, self.windowYZ_2]...
ppart3.py
Source:ppart3.py
1import cv22import numpy as np34import math567 89def createFilter(sigma, kernelSize):1011 kernel = np.zeros((kernelSize, kernelSize))12 s = 2 * (sigma * sigma)1314 for i in range(kernelSize):15 for j in range(kernelSize):16 r = math.sqrt(i ** 2 + j ** 2)17 kernel[i, j] = (math.exp(-(r * r) / s)) / (3.14 * s)1819 kernel /= np.sum(kernel)2021 return kernel2223def gaussianBlur(I):24 sigma = 225 kernel_size = 526 gaussianKernel = createFilter(sigma, kernel_size)27 rows, cols = I.shape28 blurred = I.copy()29 index = int(kernel_size / 2)30 for i in range(rows - kernel_size):31 for j in range(cols - kernel_size):32 window = I[i:i + kernel_size, j:j + kernel_size]33 temp = np.sum(np.multiply(window, gaussianKernel))34 if temp > 255:35 blurred[i:i + kernel_size, j:j + kernel_size][index][index] = 25536 elif temp < 0:37 blurred[i:i + kernel_size, j:j + kernel_size][index][index] = 038 else:39 blurred[i:i + kernel_size, j:j + kernel_size][index][index] = temp4041 return blurred4243def gradient(I):44 rows, cols = I.shape45 gx = np.zeros(I.shape)46 gy = np.zeros(I.shape)47 for i in range(rows):48 for j in range(cols):49 if i + 1 < rows and i - 1 >= 0:50 gx[i, j] = (int(I[i + 1, j]) - int(I[i - 1, j])) / 251 if j + 1 < cols and j - 1 >= 0:52 gy[i, j] = (int(I[i, j + 1]) - int(I[i, j - 1])) / 25354 return gx, gy5556def harris_corner(I, Ix, Iy, thresholdValue):57 rows, cols = I.shape58 I_WithCorner = I.copy()59 I_WithCorner = cv2.cvtColor(I_WithCorner, cv2.COLOR_GRAY2RGB)60 kernel_size = 361 Ixx = Ix ** 262 Iyy = Iy ** 263 Ixy = Ix * Iy64 k = 0.0465 index = int(kernel_size / 2)66 for i in range(index, rows - index):67 for j in range(index, cols - index):68 Windowxx = Ixx[i - index:i + index + 1, j - index:j + index + 1]69 Windowxy = Ixy[i - index:i + index + 1, j - index:j + index + 1]70 Windowyy = Iyy[i - index:i + index + 1, j - index:j + index + 1]71 Sxx = np.sum(Windowxx)72 Sxy = np.sum(Windowxy)73 Syy = np.sum(Windowyy)74 determinant = (Sxx * Syy) - (Sxy ** 2)75 trace = Sxx + Sxy76 R = determinant - k * (trace ** 2)7778 if R > thresholdValue:79 80 I_WithCorner = cv2.circle(I_WithCorner, (j, i), 3, (0, 0, 255), -1)81 return I_WithCorner8283im = cv2.imread("test.png", 0)84blurred_img = gaussianBlur(im)85im_x, im_y = gradient(blurred_img)8687threshold = 90000008889img_corner = harris_corner(blurred_img, im_x, im_y, threshold)90919293cv2.imshow("result.png", img_corner)94cv2.imwrite("part3.png",img_corner)95cv2.waitKey(0)
...
HarrisCornerDetection.py
Source:HarrisCornerDetection.py
1import cv22import numpy as np34img = cv2.imread('C:\\Users\\ajayr\\Documents\\MyProjects\\AugmentoSteer\\testImages\\understanding opencv\\chess.jfif')5gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)6mY=np.array([[-1,-1,-1],[0,0,0],[1,1,1]])7mX=np.array([[-1,0,1],[-1,0,1],[-1,0,1]])8paddedArray = np.pad(gray, pad_width=1, mode='constant', constant_values=0)9finalImage=np.zeros((len((paddedArray)-4),len((paddedArray[0])-4)))10for i in range(len(paddedArray)-3):11 for j in range(len(paddedArray[0])-3):12 13 x=paddedArray[i:i+3,j:j+3]14 WindowX=np.multiply(x,mX)15 WindowY=np.multiply(x,mY)16 WindowXX=WindowX.dot(WindowX)17 sXX=np.sum(WindowXX)18 WindowYY=WindowY.dot(WindowY)19 sYY=np.sum(WindowYY)20 WindowXY=WindowX.dot(WindowY)21 sXY=np.sum(WindowXY)22 Det = (sXX*sYY)-(sXY**2)23 Trace = (sXX+sYY)24 k=0.0425 R = Det-(k*(Trace**2))26 if(R>0):27 finalImage[i,j]=R28 if(R<=0):29 finalImage[i,j]=030cv2.imshow('final',finalImage)31cv2.imshow('original',gray)32cv2.waitKey(0)33cv2.destroyAllWindows()
...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!