def binstatus2(items): while items != [0,0,0,0]: open = door() #for each element of the items array for i in range(1, 4): #check if the object is equal to the bottom compartment category if items[i-1] == i: platenumber = i #if object matches compartment category, empty the compartment openplate() items[i] = 0 rotate() elif: rotate() if open == True: break return(items)
def next_batch(self, batch_size, phase): # Get next batch of image (path) and labels if phase == 'train': if self.train_ptr + batch_size < self.train_size: paths = self.train_image[self.train_ptr:self.train_ptr + batch_size] labels = self.train_label[self.train_ptr:self.train_ptr + batch_size] self.train_ptr += batch_size else: new_ptr = (self.train_ptr + batch_size)%self.train_size paths = self.train_image[self.train_ptr:] + self.train_image[:new_ptr] labels = self.train_label[self.train_ptr:] + self.train_label[:new_ptr] self.train_ptr = new_ptr elif phase == 'test': if self.test_ptr + batch_size < self.test_size: paths = self.test_image[self.test_ptr:self.test_ptr + batch_size] labels = self.test_label[self.test_ptr:self.test_ptr + batch_size] self.test_ptr += batch_size else: new_ptr = (self.test_ptr + batch_size)%self.test_size paths = self.test_image[self.test_ptr:] + self.test_image[:new_ptr] labels = self.test_label[self.test_ptr:] + self.test_label[:new_ptr] self.test_ptr = new_ptr else: return None, None # Read images images = np.ndarray([batch_size, self.crop_size, self.crop_size, 3]) for i in xrange(len(paths)): img = cv2.imread(paths[i]) h, w, c = img.shape assert c==3 if phase == 'train': angle = np.random.rand()*20 -10 img = rotate(img, angle) img = cv2.resize(img, (self.scale_size, self.scale_size)) img = img.astype(np.float32) img -= self.mean # shift = int((self.scale_size-self.crop_size)/2) shift1 = np.random.randint(0,self.scale_size-self.crop_size+1) shift2 = np.random.randint(0,self.scale_size-self.crop_size+1) img_crop = img[shift1:shift1+self.crop_size, shift2:shift2+self.crop_size, :] images[i] = img_crop else: img = cv2.resize(img, (self.crop_size, self.crop_size)) img = img.astype(np.float32) img -= self.mean images[i] = img # Expand labels one_hot_labels = np.zeros((batch_size, self.n_classes)) for i in xrange(len(labels)): one_hot_labels[i][labels[i]] = 1 return images, one_hot_labels
def STA(funfcn, Best, SE, Range, Iterations): alpha_max = 1 alpha_min = 1e-4 alpha = alpha_max beta = 1 gamma = 1 delta = 1 fc = 2 history = np.empty((Iterations, 1)) fBest = funfcn(Best[0]) # 用一种奇怪的方式调用矩阵中的数 for iter in range(Iterations): Best, fBest = expand(funfcn, Best, fBest, SE, Range, beta, gamma) Best, fBest = rotate(funfcn, Best, fBest, SE, Range, alpha, beta) Best, fBest = axesion(funfcn, Best, fBest, SE, Range, beta, delta) history[iter] = fBest alpha = alpha / fc if alpha > alpha_min else alpha_max return Best, fBest, history
_, head, _, tail = car # park小车车 if park(head, destination.des, 70) == 'P': comBlutooth('P', port) comBlutooth('S', port) break # rotate小车车 th = thin(img) cv2.imshow('thin', th) op, l, m, r = rotate(th, 40,22, tail, head, oldOp) oldOp = op comBlutooth(op, port) cv2.circle(img, tuple(head), 3, (0, 255, 0), -1) cv2.circle(img, tuple(tail), 3, (255, 225, 0), -1) cv2.circle(img, tuple(l), 5, (127, 0, 127), -1) cv2.circle(img, tuple(m), 5, (0, 127, 127), -1) cv2.circle(img, tuple(r), 5, (127, 127, 0), -1) cv2.imshow("l & m & r & head & tail", img) if cv2.waitKey(1) == ord('q'): comBlutooth('P', port) comBlutooth('S', port)
def teach(problem, solution, step): step_now = solution.split(' ')[step] config = [problem[i * 9:(i + 1) * 9] for i in range(6)] config = rotate(config, step_now) problem = ('').join(config) return problem
# ############## img的canny变换 @ input:img output:edges img并没有变化 # cv2.imshow('edges', edges) # ############## img的canny变换 @ input:img output:edges img并没有变化 undistorted_img = img[0:90, 0:90] cv2.imshow('undistorted_img', undistorted_img) if img[45 - kuandu:45 + kuandu, 0:90].sum() / 255 - 2 * kuandu * 90 * baifenbi >= 0 and img[ 0:90, 45 - kuandu:45 + kuandu].sum() / 255 - 2 * kuandu * 90 * baifenbi: shiziflag = 1 else: shiziflag = 0 # *** *** *** *** 十字检测任何时刻都在检测,没有flag # ———————————————————————————————————————————————————————————————————— loc[1], shuzhe[1] = guoxian(undistorted_img, 0, shuzhe[1]) loc[2], shuzhe[2] = guoxian(rotate(undistorted_img, 10), 0, shuzhe[2]) loc[3], shuzhe[3] = guoxian(rotate(undistorted_img, -10), 0, shuzhe[3]) shuzhe[0][0] = shuzhe[0][1] shuzhe[0][1] = shuzhe[0][2] shuzhe[0][2] = max(shuzhe[1][2], shuzhe[2][2], shuzhe[3][2]) finalloc = [] loc[0] = [loc[1], loc[2], loc[3]] for i in loc[0]: if str(i) == 'nan': continue else: finalloc.append(i) if len(finalloc) == 0: finalloc = np.nan
lower = np.array(lower, dtype="uint8") upper = np.array(upper, dtype="uint8") mask = cv2.inRange(img, lower, upper) img = cv2.bitwise_and(img, img, mask=mask) # ############## img的色彩提取 @ input:img output:img img = cv2.resize(img, DIM) map1, map2 = cv2.fisheye.initUndistortRectifyMap(K, D, np.eye(3), K, DIM, cv2.CV_16SC2) img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT) # ############## img的畸变矫正 @ input:img output:img cv2.imshow('img', img) cv2.imshow('rotate', rotate(img, 10)) # cv2.imshow('imgcopy', img[0:160, 0:90]) # img = img[0:90, 0:90] img = rotate(img, 10) img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) wtf, img = cv2.threshold(img, 120, 255, cv2.THRESH_BINARY) # cv2.imshow('erzhi', img) # ############## img灰度化加二值化 # input:img output:img cany = cv2.GaussianBlur(img, (13, 13), 0) edges = cv2.Canny(cany, 50, 70, apertureSize=3) # ############## img的canny变换 @ input:img output:edges img并没有变化 cv2.imshow('edges', edges) # ############## img的canny变换 @ input:img output:edges img并没有变化 undistorted_img = img cv2.imshow('shizi', img) if img[45 - kuandu:45 + kuandu,