def get_new_grasp_points_position(points,foldLine): mirrored_pts = [] for pt in points: if(pt != None): mirrored_pts.append(Vector2D.mirror_pt(pt,Vector2D.make_ln_from_pts(foldLine[0],foldLine[1]))) else: show_message("Some of the grasp points wasn't set.", MsgTypes.exception) """ Mirroring visualisation cv.NamedWindow("Mirroring visualisation") img = img = cv.CreateImage((800,600),8,3) # axis cv.PolyLine(img,[foldLine],1,cv.CV_RGB(0,255,0),1) # source points for pt in points: intPt = (int(pt[0]),int(pt[1])) cv.Circle(img,intPt,3,cv.CV_RGB(255,0,0),2) # mirrored points for pt in mirrored_pts: intPt = (int(pt[0]),int(pt[1])) cv.Circle(img,intPt,3,cv.CV_RGB(0,0,255),2) cv.ShowImage("Mirroring visualisationn",img) cv.WaitKey() cv.DestroyWindow("Mirroring visualisation") # Mirroring visualisation """ #show_message("Move grasped points to: " + str(mirrored_pts), MsgTypes.info) return mirrored_pts
def foldDrawer(self,event,x,y,flags,param): if event==cv.CV_EVENT_LBUTTONUP: self.foldline_pts.append((x,y)) print "ADDED PT" cv.Circle(self.background,(x,y),3,cv.CV_RGB(255,0,0),-1) if len(self.foldline_pts) >= 2: self.foldline = Vector2D.make_ln_from_pts(self.foldline_pts[0],self.foldline_pts[1]) ln_start = Vector2D.intercept(self.foldline,Vector2D.horiz_ln(y=0)) ln_end = Vector2D.intercept(self.foldline,Vector2D.horiz_ln(y=self.background.height)) cv.Line(self.background,(int(ln_start[0]),int(ln_start[1])),(int(ln_end[0]),int(ln_end[1])),cv.CV_RGB(0,0,0)) self.has_foldline = True elif len(self.foldline_pts) > 0: self.addTempCVShape(CVLineSegment(cv.CV_RGB(255,255,255),2,Geometry2D.LineSegment(Geometry2D.Point(self.foldline_pts[0][0],self.foldline_pts[0][1]),Geometry2D.Point(x,y))))
def get_folded_model(self,foldLine): #do the fold line # A function Vector2D.intercept doesnt work if x or y of pts are same. Therofre I put some noise if neded noise = -1; difX = (foldLine[0])[0] - (foldLine[1])[0] difY = (foldLine[0])[1] - (foldLine[1])[1] if ((difX == 0) and (difY == 0)): self.foldline_pts.append( ((foldLine[0])[0]+noise,(foldLine[0])[1]+noise) ) elif(difX == 0): self.foldline_pts.append( ((foldLine[0])[0]+noise,(foldLine[0])[1]) ) elif(difY == 0): self.foldline_pts.append( ((foldLine[0])[0],(foldLine[0])[1]+noise) ) else: self.foldline_pts.append(foldLine[0]) self.foldline_pts.append(foldLine[1]) self.foldline = Vector2D.make_ln_from_pts(self.foldline_pts[0],self.foldline_pts[1]) ln_start = Vector2D.intercept(self.foldline,Vector2D.horiz_ln(y=0)) ln_end = Vector2D.intercept(self.foldline,Vector2D.horiz_ln(y=self.background.height)) #visualisation cv.Line(self.background,(int(ln_start[0]),int(ln_start[1])),(int(ln_end[0]),int(ln_end[1])),cv.CV_RGB(0,0,0)) cv.Circle(self.background,self.foldline_pts[0],4,cv.CV_RGB(0,255,0)) cv.Circle(self.background,self.foldline_pts[1],4,cv.CV_RGB(0,255,0)) cv.Circle(self.background,(int(ln_start[0]),int(ln_start[1])),4,cv.CV_RGB(255,0,0)) cv.Circle(self.background,(int(ln_end[0]),int(ln_end[1])),4,cv.CV_RGB(255,0,0)) cv.ShowImage("Fold visualisation",self.background ) cv.WaitKey() cv.DestroyWindow("Fold visualisation") model = Models.Point_Model_Folded(self.initial_model,self.foldline_pts[0],self.foldline_pts[1]) model.draw_to_image(self.background,cv.RGB(255,0,0)) if model.illegal() or model.structural_penalty() >= 1.0: print "Model is illegal!" return None else: return model
def draw_line(img,pt1,pt2): line = Vector2D.make_ln_from_pts(pt1,pt2) ln_start = Vector2D.intercept(line,Vector2D.horiz_ln(y=0)) ln_end = Vector2D.intercept(line,Vector2D.horiz_ln(y=img.height)) cv.Line(img,ln_start,ln_end,cv.CV_RGB(255,0,0),2)
def draw_line(img, pt1, pt2): line = Vector2D.make_ln_from_pts(pt1, pt2) ln_start = Vector2D.intercept(line, Vector2D.horiz_ln(y=0)) ln_end = Vector2D.intercept(line, Vector2D.horiz_ln(y=img.height)) cv.Line(img, ln_start, ln_end, cv.CV_RGB(255, 0, 0), 2)