How to use flake method in prospector

Best Python code snippet using prospector_python

template_matching_batch.py

Source:template_matching_batch.py Github

copy

Full Screen

1#!/usr/bin/env python32# -*- coding: utf-8 -*-3"""4Created on Tue Sep 15 12:21:25 20205@author: ranjana6"""7# 1st import the package and check its version8import MTM9print("MTM version : ", MTM.__version__)10from MTM import matchTemplates, drawBoxesOnRGB11import cv212from skimage import io13import matplotlib.pyplot as plt14import numpy as np15import pandas as pd16from MTM.NMS import NMS17import os18from tqdm import tqdm19import glob20#files1= glob.glob('D:\\video_template\\temp\\*.jpg')########### path for all template21files1= glob.glob('./temp_store3/*.jpg')22#files= glob.glob('D:\\video_template\\image\\*.jpg')############## path for all images folder from video23files= glob.glob('./PMI_S3_15-09-2020-2/*.jpg')24path = './plot_15sep_1/'25total=pd.DataFrame()26#total1=pd.DataFrame() 27batch_size=10028total=pd.DataFrame()29total1=pd.DataFrame()30for n in range((len(files)//batch_size)+1):31 for file in tqdm(files[n*batch_size:(n+1)*batch_size]):32 #for file in files:33 image = io.imread(file,0)########## reading image34 #image = image[ 16:500, 165:500] ################crop the image35 image = image[ 0:350, 110:300] ###################### for store336 #plt.imshow(image)37 name1=file.split("/")[-1]38 name1=name1.split(".")[0]39 listTemplate = []40 for myfile in files1:41 temp0=io.imread(myfile)###########reading template42 name=myfile.split("/")[-1]43 name=name.split(".")[0]44 if name == "Stellar_var1": 45 name = "Stellar"46 if ((name == "Marlboro_gold_var1") or (name == "Marlboro_gold_var2")):47 name = "Marlboro_gold"48 if name== "Marlboro_fusebeyond_var1":49 name = "Marlboro_fusebeyond"50 if name == "Stellar_define_var1":51 name ="Stellar_define"52 if name =="clove_mix_var1":53 name = "clove_mix"54 if name =="Wills_navycut_var1":55 name = "Wills_navycut"56 if ((name =="Berkeley_var1") or (name =="Berkeley_var2") or57 (name =="Berkeley_var3")):58 name = "Berkeley"59 if ((name =="Mini_Light_var1") or (name =="Mini_Light_var2") or60 (name =="Mini_Light_var3")):61 name = "Mini_Light"62 63 if ((name =="Marlboro_compact_var1") or (name =="Marlboro_compact_var2") or64 (name =="Marlboro_compact_var3") or (name =="Marlboro_compact_var4")):65 name = "Marlboro_compact"66 if ((name =="Flake_premium_var1") or(name =="Flake_premium_var2") or67 (name == "Flake_premium_var3")):68 name="Flake_premium"69 if ((name =="GoldFlake_Luxury King_var1") or(name =="GoldFlake_Luxury King_var2") or70 (name == "GoldFlake_Luxury King_var4")):71 name = "GoldFlake_Luxury King"72 if ((name== "B&H_var1") or(name=="B&H_var2") or73 (name== "B&H_var3") or (name== "B&H_var4") or74 (name== "B&H_var5") or (name== "B&H_var6") or75 (name == "B&H_var7")):76 name = "B&H"77 if ((name== "Marlboro_adv_var1") or(name=="Marlboro_adv_var2") or78 (name== "Marlboro_adv_var3") or (name== "Marlboro_adv_var4") or79 (name== "Marlboro_adv_var5") or (name== "Marlboro_adv_var6")):80 name = "Marlboro_adv"81 if ((name== "Classic_mild_var1") or(name=="Classic_mild_var2") or82 (name== "Classic_mild_var3") or (name== "Classic_mild_var4") or83 (name== "Classic_mild_var5") or (name== "Classic_mild_var6")):84 name = "Classic_mild"85 if ((name== "Classic_menthol_var1") or(name=="Classic_menthol_var2") or86 (name== "Classic_menthol_var3") or (name== "Classic_menthol_var4") or87 (name== "Classic_menthol_var5") or (name== "Classic_menthol_var6")):88 name = "Classic_menthol"89 if ((name== "Classic_iceburst_var1") or(name=="Classic_iceburst_var2") or90 (name== "Classic_iceburst_var3") or (name== "Classic_iceburst_var4")):91 name = "Classic_iceburst"92 if ((name== "Classic_ultramild_var1") or(name=="Classic_ultramild_var2") or93 (name== "Classic_ultramild_var3") or (name== "Classic_ultramild_var4") or94 (name== "Classic_ultramild_var5") or (name== "Classic_ultramild_var6") or95 (name== "Classic_ultramild_var7") or (name== "Classic_ultramild_var8") or96 (name== "Classic_ultramild_var9") or (name== "Classic_ultramild_var10")):97 name = "Classic_ultramild"98 if ((name== "Classic_regular_var1") or(name=="Classic_regular_var2") or99 (name== "Classic_regular_var3") or (name== "Classic_regular_var4") or100 (name== "Classic_regular_var5")):101 name = "Classic_regular"102 if ((name== "GoldFlake_King_var1") or(name=="GoldFlake_King_var2") or103 (name== "GoldFlake_King_var3") or (name== "GoldFlake_King_var4") or104 (name== "GoldFlake_King_var5") or (name== "GoldFlake_King_var6") or105 (name== "GoldFlake_King_var7") or (name== "GoldFlake_King_var8") or106 (name == "GoldFlake_King_var9") or (name == "GoldFlake_King_var10")or 107 (name == "GoldFlake_King_var11") or (name == "GoldFlake_King_var12")or 108 (name == "GoldFlake_King_var13") or (name == "GoldFlake_King_var14") or109 (name == "GoldFlake_King_var15") or (name == "GoldFlake_King_var16") or110 (name == "GoldFlake_King_var17") or (name == "GoldFlake_King_var18")or111 (name == "GoldFlake_King_var19") or (name == "GoldFlake_King_var20") or112 (name == "GoldFlake_King_var21") or (name == "GoldFlake_King_var22") or113 (name == "GoldFlake_King_var23") or (name == "GoldFlake_King_var24") or114 (name == "GoldFlake_King_var25") or (name == "GoldFlake_King_var26")or115 (name == "GoldFlake_King_var27") or (name == "GoldFlake_King_var28") or116 (name == "GoldFlake_King_var29") or (name == "GoldFlake_King_var30") or117 (name == "GoldFlake_King_var31") or (name == "GoldFlake_King_var32") or118 (name == "GoldFlake_King_var33") or (name == "GoldFlake_King_var34")):119 name="GoldFlake_King"120 if ((name== "King_Light_var1") or(name=="King_Light_var2") or121 (name== "King_Light_var3") or (name== "King_Light_var4") or122 (name== "King_Light_var5") or (name== "King_Light_var6") or123 (name== "King_Light_var7") or (name== "King_Light_var8") or124 (name == "King_Light_var9") or (name == "King_Light_var10") or125 (name == "King_Light_var11") or (name == "King_Light_var12") or126 (name == "King_Light_var13") or (name == "King_Light_var14") or127 (name == "King_Light_var15") or (name == "King_Light_var16")):128 name="King_Light"129 #print("name of box",name)130 listTemplate.append( (name, temp0)) 131 for myfile in files1:132 temp0=io.imread(myfile)133 name=myfile.split("/")[-1]134 name=name.split(".")[0]135 if name == "Stellar_var1": 136 name = "Stellar"137 if ((name == "Marlboro_gold_var1") or (name == "Marlboro_gold_var2")):138 name = "Marlboro_gold"139 if name== "Marlboro_fusebeyond_var1":140 name = "Marlboro_fusebeyond"141 if name == "Stellar_define_var1":142 name ="Stellar_define"143 if name =="clove_mix_var1":144 name = "clove_mix"145 if name =="Wills_navycut_var1":146 name = "Wills_navycut"147 if ((name =="Berkeley_var1") or (name =="Berkeley_var2") or148 (name =="Berkeley_var3")):149 name = "Berkeley"150 if ((name =="Mini_Light_var1") or (name =="Mini_Light_var2") or151 (name =="Mini_Light_var3")):152 name = "Mini_Light"153 154 if ((name =="Marlboro_compact_var1") or (name =="Marlboro_compact_var2") or155 (name =="Marlboro_compact_var3") or (name =="Marlboro_compact_var4")):156 name = "Marlboro_compact"157 if ((name =="Flake_premium_var1") or(name =="Flake_premium_var2") or158 (name == "Flake_premium_var3")):159 name="Flake_premium"160 if ((name =="GoldFlake_Luxury King_var1") or(name =="GoldFlake_Luxury King_var2") or161 (name == "GoldFlake_Luxury King_var4")):162 name = "GoldFlake_Luxury King"163 if ((name== "B&H_var1") or(name=="B&H_var2") or164 (name== "B&H_var3") or (name== "B&H_var4") or165 (name== "B&H_var5") or (name== "B&H_var6") or166 (name == "B&H_var7")):167 name = "B&H"168 if ((name== "Marlboro_adv_var1") or(name=="Marlboro_adv_var2") or169 (name== "Marlboro_adv_var3") or (name== "Marlboro_adv_var4") or170 (name== "Marlboro_adv_var5") or (name== "Marlboro_adv_var6")):171 name = "Marlboro_adv"172 if ((name== "Classic_mild_var1") or(name=="Classic_mild_var2") or173 (name== "Classic_mild_var3") or (name== "Classic_mild_var4") or174 (name== "Classic_mild_var5") or (name== "Classic_mild_var6")):175 name = "Classic_mild"176 if ((name== "Classic_menthol_var1") or(name=="Classic_menthol_var2") or177 (name== "Classic_menthol_var3") or (name== "Classic_menthol_var4") or178 (name== "Classic_menthol_var5") or (name== "Classic_menthol_var6")):179 name = "Classic_menthol"180 if ((name== "Classic_iceburst_var1") or(name=="Classic_iceburst_var2") or181 (name== "Classic_iceburst_var3") or (name== "Classic_iceburst_var4")):182 name = "Classic_iceburst"183 if ((name== "Classic_ultramild_var1") or(name=="Classic_ultramild_var2") or184 (name== "Classic_ultramild_var3") or (name== "Classic_ultramild_var4") or185 (name== "Classic_ultramild_var5") or (name== "Classic_ultramild_var6") or186 (name== "Classic_ultramild_var7") or (name== "Classic_ultramild_var8") or187 (name== "Classic_ultramild_var9") or (name== "Classic_ultramild_var10")):188 name = "Classic_ultramild"189 if ((name== "Classic_regular_var1") or(name=="Classic_regular_var2") or190 (name== "Classic_regular_var3") or (name== "Classic_regular_var4") or191 (name== "Classic_regular_var5")):192 name = "Classic_regular"193 if ((name== "GoldFlake_King_var1") or(name=="GoldFlake_King_var2") or194 (name== "GoldFlake_King_var3") or (name== "GoldFlake_King_var4") or195 (name== "GoldFlake_King_var5") or (name== "GoldFlake_King_var6") or196 (name== "GoldFlake_King_var7") or (name== "GoldFlake_King_var8") or197 (name == "GoldFlake_King_var9") or (name == "GoldFlake_King_var10")or 198 (name == "GoldFlake_King_var11") or (name == "GoldFlake_King_var12")or 199 (name == "GoldFlake_King_var13") or (name == "GoldFlake_King_var14") or200 (name == "GoldFlake_King_var15") or (name == "GoldFlake_King_var16") or201 (name == "GoldFlake_King_var17") or (name == "GoldFlake_King_var18")or202 (name == "GoldFlake_King_var19") or (name == "GoldFlake_King_var20") or203 (name == "GoldFlake_King_var21") or (name == "GoldFlake_King_var22") or204 (name == "GoldFlake_King_var23") or (name == "GoldFlake_King_var24") or205 (name == "GoldFlake_King_var25") or (name == "GoldFlake_King_var26")or206 (name == "GoldFlake_King_var27") or (name == "GoldFlake_King_var28") or207 (name == "GoldFlake_King_var29") or (name == "GoldFlake_King_var30") or208 (name == "GoldFlake_King_var31") or (name == "GoldFlake_King_var32") or209 (name == "GoldFlake_King_var33") or (name == "GoldFlake_King_var34")):210 name="GoldFlake_King"211 if ((name== "King_Light_var1") or(name=="King_Light_var2") or212 (name== "King_Light_var3") or (name== "King_Light_var4") or213 (name== "King_Light_var5") or (name== "King_Light_var6") or214 (name== "King_Light_var7") or (name== "King_Light_var8") or215 (name == "King_Light_var9") or (name == "King_Light_var10") or216 (name == "King_Light_var11") or (name == "King_Light_var12") or217 (name == "King_Light_var13") or (name == "King_Light_var14") or218 (name == "King_Light_var15") or (name == "King_Light_var16")):219 name="King_Light"220 #print("name of box",name)221 for i,angle in enumerate([90,180]):222 rotated = np.rot90(temp0, k=i+1) # NB: rotate not good here, turns into float!223 listTemplate.append( (name, rotated ) )224 225 im=image226 #Hits = matchTemplates(listTemplate, im,N_object=34, score_threshold=0.5, method=cv2.TM_CCOEFF_NORMED, maxOverlap=0.25)227 #print(Hits)228 # Generate gaussian distributed noise, the noise intensity is set by the level variable229 noise = np.empty_like(im, dtype="int8")230 level = 10231 cv2.randn(noise,(0),(level)) # Matrix element are 0 in average232 imageNoise = cv2.add(im,noise, dtype=cv2.CV_8U)233 Hits_Noise = matchTemplates(listTemplate, imageNoise,score_threshold=0.75, method=cv2.TM_CCOEFF_NORMED, maxOverlap=0.2,searchBox=None)##########without using N_object234 #Hits_Noise = matchTemplates(listTemplate, imageNoise,N_object=20,score_threshold=0.001, method=cv2.TM_CCOEFF_NORMED, maxOverlap=.08,searchBox=None)235 H=Hits_Noise236 df=Hits_Noise.reset_index()237 w = df["BBox"].str[2]238 h = df["BBox"].str[3]239 df["width"] = round(w * 2.54 / 96,1)240 df["hight"] = round(h * 2.54 / 96,1)241 #score=max(df.Score)242 f1=df.TemplateName.unique()243 br1=df['TemplateName'].value_counts().reset_index()244#df.to_csv("output.csv",index=False)245 df3=pd.DataFrame(columns=["index","TemplateName","BBox","Score","width","hight"])246 for i in range(0,len(br1.TemplateName)):247 df1=df[df.TemplateName ==f1[i]]248 score=round(max(df1.Score),2)249 score1=round((score-0.35),2)250 df2=df1[(df1.Score == score) | (df1.Score >= score1)]251 df3=df3.append(df2)252 df3["name"]=name1253 #df3.to_csv(name1+".csv",index=False)254 255 #Overlay1 = drawBoxesOnRGB(im, finalHits,showLabel=True,labelScale=0.4,labelColor=(0, 255, 255), boxThickness=2)256 Overlay2 = drawBoxesOnRGB(imageNoise,df3,showLabel=True,labelScale=0.3,labelColor=(0, 255, 255), boxThickness=2)###########draw the box on image257 #path=r'D:\video_template\plots'###############path to save image258 # plt.savefig(path+"\\"+name1+'.png')259 plt.figure(figsize = (20,20))260 plt.axis("off")261 plt.imshow(Overlay2)262 plt.savefig(path+"/"+name1+'.png')263 plt.close()264 br=df3[['TemplateName','name']]265 s2=br.pivot_table(index=['name'], columns=['TemplateName'], aggfunc=len).fillna(0).reset_index()266 #br2=br.groupby(["name",'TemplateName']).size().reset_index(name="Time")267 #br2=df3['TemplateName'].value_counts().reset_index()268 #br2.to_csv(name1+"_1.csv",index=False)269 #total1=s_t1.append(br2)270 total=total.append(s2)271 total.to_csv("all"+"_1.csv",index=False)...

Full Screen

Full Screen

SnowFlake_v1.py

Source:SnowFlake_v1.py Github

copy

Full Screen

...97 iter = iter+0.5 # slightly oversample because I lack faith.9899def perform(level, box, options):100 ''' Feedback to abrightmoore@yahoo.com.au '''101 Snowflake(level, box, options) 102 level.markDirtyBox(box)103 104def Snowflake(level, box, options):105 # CONSTANTS AND GLOBAL VARIABLES106 method = "RIBBON"107 print '%s: Started at %s' % (method, time.ctime())108 (width, height, depth) = getBoxSize(box)109 centreWidth = width / 2110 centreHeight = height / 2111 centreDepth = depth / 2112 material = (options["Material:"].ID, options["Material:"].blockData)113 (blockID, blockData) = material114 Colours = [0, 0, 0,11,3,10, 14,1,4,5]115 # END CONSTANTS116117 # Make a 2D snowflake with 4 lines of symmetry (i.e. 6 equal arcs)118 # So.. do it once, then rotate into position at 45 degrees, then replicate in the other 3 quadrants. ...

Full Screen

Full Screen

01_snowfall.py

Source:01_snowfall.py Github

copy

Full Screen

...4# - создание снежинки с нужными параметрами5# - отработку изменений координат6# - отрисовку7# x, y = 0, 08# flake = Snowflake(flake_x=100, flake_y=600, length_flake=sd.random_number(5, 15))9#10# while True:11# for i in range(flake.step_y):12# flake.clear_previous_picture()13# flake.move()14# print("Снежинка падает на шаге", i)15# flake.draw()16# sd.sleep(0.1)17# if not flake.can_fall():18# break19# sd.sleep(0.1)20#21# if sd.user_want_exit():22# break23class Snowflake:24 def __init__(self, flake_x, flake_y, length_flake):25 self.length = length_flake26 self.y = flake_y27 self.x = flake_x28 self.point = sd.get_point(x=self.x, y=self.y)29 self.color = sd.COLOR_WHITE30 self.factor_a = 0.631 self.factor_b = 0.3532 self.factor_c = 6033 self.step_y = self.y // self.length + 134 def clear_previous_picture(self):35 self.color = sd.background_color36 sd.snowflake(center=self.point, length=self.length, color=self.color, factor_a=self.factor_a,37 factor_b=self.factor_b)38 def move(self):39 self.y -= self.length40 self.point = sd.get_point(x=self.x, y=self.y)41 def draw(self):42 self.color = sd.COLOR_WHITE43 sd.snowflake(center=self.point, length=self.length, color=self.color, factor_a=self.factor_a,44 factor_b=self.factor_b)45 def can_fall(self):46 return self.y <= 047def get_flakes(N): # Создание списка снежинок48 flakes = []49 for i in range(N):50 flake_x = sd.random_number(0, 600)51 flake_y = 65052 flake = Snowflake(flake_x, flake_y, length_flake=sd.random_number(5, 15))53 flakes.append(flake)54 return flakes55def append_flakes(count=None):56 for i in count:57 flake_x = sd.random_number(0, 600)58 flake_y = 65059 flake = Snowflake(flake_x, flake_y, length_flake=sd.random_number(5, 15))60 flakes.insert(i, flake)61 return flakes62def get_fallen_flakes(flakes): # подсчет упавших снежинок63 fallen_flakes = []64 for index, value in enumerate(flakes):65 if value.can_fall():66 fallen_flakes.append(index)67 return fallen_flakes68def remove_flakes(fallen_flakes):69 fallen_flakes.reverse()70 for index, value in enumerate(fallen_flakes):71 del flakes[value]72N = 5073fallen_flakes = []...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run prospector automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful