def actually_solve_math_function(self, math_function): ''' :param math_function: :return: ''' # TODO: DEBUGGING print "Solving:", get_math_function_as_string(math_function), ''' If the function is already just a number, return it. ''' has_operations = False for x in range(len(math_function)): current = math_function[x] if current == '^' or current == '*' or current == '/' or current == '+' or current == '-': has_operations = True if not has_operations: return math_function[0] else: if self.solve_for_operator('^', math_function) == False: return False self.solve_for_operator('*', math_function) if self.solve_for_operator('/', math_function) == False: return False self.solve_for_operator('+', math_function) self.solve_for_operator('-', math_function) if len(math_function) != 1: print "Critical Error, the math function didn't have a length of 1." MyTimer.terminate_program() else: return math_function[0]
def __init__(self, can, poids, coeff, py0, px0): self.can = can self.poids = poids self.py0 = py0 self.px0 = px0 self.py = py0 self.px = px0 self.coeff = coeff self.moov = 0 self.timer = MyTimer(0.001, self.deplace)
def attempt_solution(self): expression = "" if self.data_constant[0]: expression = "f(x) = " + str(self.data[0][0]) elif self.data_constant[1]: expression = "f(x) = " + str(self.data[0][0]) + " + x * " + str(self.data[1][0]) elif self.data_constant_multiplier[0]: expression = "f(x) = " + str(self.data[0][0]) + " * (" + str(self.data_multiplier[0][0]) + " ^ x)" if expression != "": print expression MyTimer.terminate_program()
def __init__(self, can, poids, coeff, py0, px0): self.can = can; self.poids = poids self.py0 = py0 self.px0 = px0 self.py = py0 self.px = px0 self.coeff = coeff self.moov = 0 self.timer = MyTimer(0.001, self.deplace)
class ObjetDeLaVie: """Unobjet avec les propriete Newton""" def __init__(self, can, poids, coeff, py0, px0): self.can = can self.poids = poids self.py0 = py0 self.px0 = px0 self.py = py0 self.px = px0 self.coeff = coeff self.moov = 0 self.timer = MyTimer(0.001, self.deplace) def shoot(self, vitesse, angle): self.angle = angle self.vitesse = vitesse self.vx = cos(self.angle * 0.0174) * vitesse self.vy = sin(self.angle * 0.0174) * vitesse self.tps = 0 self.timer.start() def deplace(self): self.moov = 1 if (self.vitesse > 2): if (self.py > 340): self.timer.stop() self.px0 = self.px self.py0 = 340 self.vitesse *= self.coeff self.shoot(self.vitesse, self.angle) if (self.px < -20): self.vx = -self.vx self.px = -20 self.angle = self.angle - 2 * (self.angle - 90) self.px0 = -20 - self.px0 elif (self.px > 1000): self.vx = -self.vx self.px = 1000 self.angle = self.angle - 2 * (self.angle - 90) self.px0 = 2 * 1000 - self.px0 if (self.px >= -20 and self.px <= 1000): self.px = self.vx * self.tps + self.px0 self.py = ( (self.poids * 9.81) / 2) * self.tps * self.tps - self.vy * self.tps + self.py0 self.can.coords(self.image, self.px, self.py) self.tps += 0.018 else: self.moov = 0 self.timer.stop()
class ObjetDeLaVie: """Unobjet avec les propriete Newton""" def __init__(self, can, poids, coeff, py0, px0): self.can = can; self.poids = poids self.py0 = py0 self.px0 = px0 self.py = py0 self.px = px0 self.coeff = coeff self.moov = 0 self.timer = MyTimer(0.001, self.deplace) def shoot(self, vitesse, angle): self.angle = angle self.vitesse = vitesse self.vx = cos(self.angle * 0.0174) * vitesse self.vy = sin(self.angle * 0.0174) * vitesse self.tps = 0 self.timer.start() def deplace(self): self.moov = 1 if (self.vitesse > 2): if (self.py > 340): self.timer.stop() self.px0 = self.px self.py0 = 340 self.vitesse *= self.coeff self.shoot(self.vitesse, self.angle) if (self.px < -20): self.vx = -self.vx self.px = -20 self.angle = self.angle - 2*(self.angle - 90) self.px0 = -20 - self.px0 elif (self.px > 1000): self.vx = -self.vx self.px = 1000 self.angle = self.angle - 2*(self.angle - 90) self.px0 = 2*1000 - self.px0 if (self.px >= -20 and self.px <= 1000): self.px = self.vx*self.tps + self.px0 self.py = ((self.poids*9.81)/2)*self.tps*self.tps - self.vy*self.tps + self.py0 self.can.coords(self.image, self.px, self.py) self.tps += 0.018 else: self.moov = 0 self.timer.stop()
lsqe = el.LSqEllipse() lsqe.fit(data) center, width, height, phi = lsqe.parameters() a = max(width, height) b = min(width, height) area = math.pi * a * b eccentricity = pow((1 - (b / a)**2), 1 / 2) pore_opening_degree = b / a return a, b, area, eccentricity, pore_opening_degree if __name__ == "__main__": import os base_path = r"C:\Users\LJY\Desktop\第一篇小论文-第二阶段\cropped_stomata\cropped_det" # 计时开始 mytime = MyTimer.MyTimer() mytime.start() # 先统计一下 path = r"D:\Mask_RCNN\mask_rcnn\cropped_stomata\first_time" # image_num 是 f image_num = len([ lists for lists in os.listdir(path) if os.path.isdir(os.path.join(path, lists)) ]) # pore_num 是 s,表示总共有多少个匹配气孔 pore_num = 0 for img in range(image_num): dirname = r"D:\Mask_RCNN\mask_rcnn\cropped_stomata\first_time\{}".format( img) filenum = len([
print __name__, "start ..." max = 20 fig = plt.figure() ax = fig.add_subplot(111) # some X and Y data li, = ax.plot(x, y, 'r.') # draw and show it fig.canvas.draw() plt.ylim((-5,25)) plt.show(block=False) HOST, PORT = "192.168.0.123", 9998 timer = MyTimer.MyTimer() print timer print "start server" # Create the server, binding to localhost on port 9999 server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler) server_thread = threading.Thread(target=server.serve_forever) # Exit the server thread when the main thread terminates server_thread.daemon = True server_thread.start() print "start drawer" drawer = PlotDrawer() drawer_thread = threading.Thread(target=drawer.run) # Exit the server thread when the main thread terminates
def run(self): #获取全局变量数据并更新全局数据 self.info = gl.GL_VInfo self.model = gl.GL_Model self.isEnd = False gl.GL_TalScore = 0 #清空全局队列 while gl.GL_CurScoreQueue.empty() == False: gl.GL_CurScoreQueue.get() startTimer = MyTimer() startTimer.start(1000) #开始计时 temp = 0 for oneInfo in self.info: timeid = oneInfo['timeid'] #演示视频播放时间ms reactime = float(oneInfo['reactime']) #反应时间 poseSocre = oneInfo['score'] #分数 posepoints = oneInfo['posepoints'] #关节点信息 posepoints = mxnet.nd.array(posepoints) #类型转换 temp += 1 print('*************这是第{}次'.format(temp)) print("timeid={}".format(timeid)) startTimer.resetWaitTime(timeid) #设置等待时间 startTimer.waitTimeOut() #等待时间,相当于 sleep self.now_to_getImages.emit() #发送截取视频图像的信号 #等待截取的图片存入全局变量 while bool(gl.GL_Images == []) | bool( gl.GL_Images.__len__() < gl.GL_Images_Length): if self.isEnd == True: #当需要线程关闭时,退出 break time.sleep(0.02) if self.isEnd == True: #当需要线程关闭时,退出 break images = gl.GL_Images #获取全局变量 (截取的图片list) #跟新全局变量数据 gl.GL_Images = [] gl.GL_Images_Length = 0 use_gpu = False maxScore = 0 score = 0 #给每一个图片匹配示范骨架,获取最大分数 for image in images: if self.isEnd == True: break playerPre, playerImage = net.detection(self.model, image, use_gpu) #模型预测骨架 if playerPre != None: playerDis, playerSkeleton = tools.normalization( playerPre['pred_coords'][0]) #结果归一化 score = tools.matching(playerSkeleton, posepoints, use_gpu=use_gpu) #计算匹配结果 if maxScore < score: maxScore = score if self.isEnd == True: break print("mxScore={}".format(maxScore)) #当分数超过10,认定匹配成功 if maxScore > 10: #将分数更新在全局变量中 gl.GL_CurScoreQueue.put(poseSocre) gl.GL_TalScore += poseSocre self.update_date.emit(poseSocre) #发送信号,传递动作得分 else: self.update_date.emit(0) #发送信号,传递动作得分 startTimer.end()
# |-test # |-|-test # |-|-|-***.png # |-|=annotations # |-|-|-***.json dataset_test.load_coco(r"D:\Mask_RCNN\mask_rcnn\测试银杏的参数数据集\test2017", "test2017") dataset_test.prepare() # image_ids 是记录test_datasets中共有多少张图片 image_ids = dataset_test.image_ids IoU_all_photos = np.zeros((1, len(image_ids))) all_statistic = np.zeros((2, len(image_ids))) count_statistic = np.zeros((2, len(image_ids))) # 计时 t1 = MyTimer.MyTimer() t1.start() # 测试集 for f in range(len(image_ids)): image_id = f info = dataset_test.image_info[image_id] print("image ID: {}.{} ({}) {}".format( info["source"], info["id"], image_id, dataset_test.image_reference(image_id))) # 原demo在使用图像之前已经对图像进行了裁剪 具体代码在model的1224行 image, image_meta, gt_class_id, gt_bbox, gt_mask = modellib.load_image_gt( dataset_test, config, image_id, use_mini_mask=False) # image 是 3D图像 [image]是4-D列表 len([image]) = 1 [image]代表把整个图像作为一个batch处理 results = model.detect([image], verbose=1) # 这里的model.detect
__author__ = 'utarsuno' # Regular Expression library being using to parse Strings (specifically to split a string by a denominator). import re # Self made library to derive the derivatives from the data. from Derivative import Derivative # Self made library to generate all possible functions to a character limit in hopes of finding a match to the data. from FunctionGenerator import FunctionGenerator # Self made library used for timing the program's speed. import MyTimer ''' Obtain the data to analyze. ''' user_input = raw_input("Enter the numbers to be analyzed: ") MyTimer.initiate_timer() ''' Parse the data based off commas. ''' user_input = re.split(",", user_input) ''' Convert the data from a string array to an int array ''' user_input = map(int, user_input) ''' Make sure user input is more than one number. ''' if len(user_input) <= 1: print "Too few inputs provided. Program will now terminate." MyTimer.terminate_program() derivative = Derivative(user_input) data = derivative.get_data()
def get_camera_images(self): ''' 截取摄像头图片,存入全局变量中 ''' reactTimer = MyTimer() waitTimer = MyTimer() reactTime = 0.5 imageSize = (640, 480) images = [] reactTime = int(reactTime * 1000) reactTimer.start(reactTime) waitTime = 100 while reactTimer.isTimeOut() == False: waitTimer.start(waitTime) flag, image = self.cap.read() image = cv2.resize(image, imageSize) images.append(image) waitTimer.waitTimeOut() gl.GL_Images = images gl.GL_Images_Length = images.__len__() print("length={}".format(images.__len__()))
import sys,MyTimer reps = 10000 repslist = range(reps) def forLoop(): res = [] for x in repslist: res.append(x + 10) return res def listComp(): return [x + 10 for x in repslist] def mapCall(): return list(map(lambda x: x + 10,repslist)) def genExpr(): return list(x + 10 for x in repslist) def genFunc(): def gen(): for x in repslist: yield x + 10 return list(gen()) print(sys.version) for test in (forLoop,listComp,mapCall,genExpr,genFunc): elapsed,result = MyTimer.timer(test) print ('-'*33) print('%-9s: %.5f => [%s...%s]' %(test.__name__,elapsed,result[0],result[-1]))
def attempt_to_find_math_function_for_data(self): #NOTE IN THE FUTURE HAVE A PARAMETER FOR NUMBER OF DIGITS: character_limit """ There are X main steps to this program. 0x1. Generate random sudo math functions. 0x2. Ignore sudo math functions that are invalid. 0x3. Prepare the sudo math function conversion. 0x4. Convert the sudo math function to a math function and test it. :return: The math function if it was found. Otherwise return 'f(x)'. """ character_limit = 6 ''' 0x1 ''' # This is the maximum number of different possible characters in the sudo math function. # TODO: Change this variable name to sudo characters. number_of_unique_characters = 5 # Calculate the number of possible sudo functions. number_of_max_sudo_functions = number_of_unique_characters for x in range(character_limit - 1): number_of_max_sudo_functions *= number_of_unique_characters number_of_sudo_functions = 0 # Go through each possible sudo function and test it. for x in range(number_of_max_sudo_functions): # Generate a single permutation. sudo_math_function = DecimalToAnyBaseArray(x, number_of_unique_characters) # Once the sudo function is generated, map the numbers to their respective character. for y in range(len(sudo_math_function)): sudo_math_function[y] = entity_map(sudo_math_function[y]) ''' 0x2 ''' if self.verify_sudo_math_function_dbg(sudo_math_function): ''' 0x3 ''' #sudo_math_function = self.prepare_sudo_math_function_for_converstion(sudo_math_function) ''' 0x4 ''' if self.convert_sudo_math_function_to_math_functions_and_test_them(sudo_math_function): MyTimer.terminate_program() print "f(x) =", get_math_function_as_string(sudo_math_function) number_of_sudo_functions += 1 ''' Max number of subs data zero: 2 ^ x - 1 no zero: x ^ 2 + 1 + x 1: 1 2: 3 3: 7 4: 14 5: 36 6: 116 7: 379 8: 1134 ___________ NEW: 1: 2: 3: 4: 5: 6: 7: 8: ''' print "Max Number of Sudo Functions:", number_of_max_sudo_functions, "\tActual:", number_of_sudo_functions for a in range(len(self.error_list)): print a, "\t", self.error_list[a]