Beispiel #1
0
def get_axes(pts):
    if MODE == TOWEL:
        y_axis = Vector2D.normalize(Vector2D.pt_diff(pts[1],pts[0]))
        
    elif MODE == PANTS:
        y_axis = Vector2D.normalize(Vector2D.pt_diff(Vector2D.pt_scale(Vector2D.pt_sum(pts[4],pts[3]),0.5),pts[0]))
    else:
        y_axis = Vector2D.normalize(Vector2D.pt_diff(pts[5],Vector2D.pt_scale(Vector2D.pt_sum(pts[0],pts[-1]),0.5)))
    x_axis = (-1*y_axis[1],y_axis[0])
    print (x_axis,y_axis)
    return (x_axis,y_axis)
    if MODE == SWEATER or MODE == TEE:
        check_points = (0,1,2,3,4,8,9,10,11,12)
    else:
        check_points = range(len(test_pts))
Beispiel #2
0
def score(testfile, correctfile):
    test_pts = Annotating.read_anno(testfile)
    correct_pts = Annotating.read_anno(correctfile)
    net_error = 0.0
    max_error = 0.0
    rel_pts = []
    if IGNORE_COLLAR:
        if MODE == SWEATER or MODE == TEE:
            check_points = (0, 1, 2, 3, 4, 8, 9, 10, 11, 12)
        else:
            check_points = range(len(test_pts))
    else:
        check_points = range(len(test_pts))
    errors = []
    (x_axis, y_axis) = get_axes(correct_pts)
    for i in check_points:  #(1,4,8,11):#range(len(test_pts)):
        test_pt = test_pts[i]
        correct_pt = correct_pts[i]
        rel_pt = Vector2D.pt_diff(test_pt, correct_pt)
        rel_pts.append(
            (Vector2D.dot_prod(rel_pt,
                               x_axis), Vector2D.dot_prod(rel_pt, y_axis)))
        error = Vector2D.pt_distance(test_pt, correct_pt)
        errors.append(error)
    return (lst_avg(errors), rel_pts)
Beispiel #3
0
def get_axes(pts):
    if MODE == TOWEL:
        y_axis = Vector2D.normalize(Vector2D.pt_diff(pts[1], pts[0]))

    elif MODE == PANTS:
        y_axis = Vector2D.normalize(
            Vector2D.pt_diff(
                Vector2D.pt_scale(Vector2D.pt_sum(pts[4], pts[3]), 0.5),
                pts[0]))
    else:
        y_axis = Vector2D.normalize(
            Vector2D.pt_diff(
                pts[5], Vector2D.pt_scale(Vector2D.pt_sum(pts[0], pts[-1]),
                                          0.5)))
    x_axis = (-1 * y_axis[1], y_axis[0])
    print(x_axis, y_axis)
    return (x_axis, y_axis)
    if MODE == SWEATER or MODE == TEE:
        check_points = (0, 1, 2, 3, 4, 8, 9, 10, 11, 12)
    else:
        check_points = range(len(test_pts))
Beispiel #4
0
def score(testfile,correctfile):
    test_pts = Annotating.read_anno(testfile)
    correct_pts = Annotating.read_anno(correctfile)
    net_error = 0.0
    max_error = 0.0
    rel_pts = []
    if IGNORE_COLLAR:
        if MODE == SWEATER or MODE == TEE:
            check_points = (0,1,2,3,4,8,9,10,11,12)
        else:
            check_points = range(len(test_pts))
    else:
        check_points = range(len(test_pts))
    errors = []
    (x_axis,y_axis) = get_axes(correct_pts)
    for i in check_points:#(1,4,8,11):#range(len(test_pts)):
        test_pt = test_pts[i]
        correct_pt = correct_pts[i]
        rel_pt = Vector2D.pt_diff(test_pt,correct_pt)
        rel_pts.append((Vector2D.dot_prod(rel_pt,x_axis),Vector2D.dot_prod(rel_pt,y_axis)))
        error = Vector2D.pt_distance(test_pt,correct_pt)
        errors.append(error)
    return (lst_avg(errors),rel_pts)
def get_fold_line(model,i):
    show_message("GET_FOLD_LINE - begin", MsgTypes.debug)
    foldStart = None
    foldEnd = None
    
    if(TYPE == ASYMM):
        #towel
        if(i == 1):
            #Fold in half
            show_message("Model verticies " + str(model.polygon_vertices_int()), MsgTypes.info)
            [bl,tl,tr,br] = [pt for pt in model.polygon_vertices_int()][0:4]
            foldStart = Vector2D.pt_center(bl,br)
            foldEnd = Vector2D.pt_center(tl,tr)
            # make foldline little bit bigger than conture
            foldLineCenter = Vector2D.pt_center(foldStart,foldEnd)
            foldStart = Vector2D.scale_pt(foldStart,1.3,foldLineCenter)
            foldEnd = Vector2D.scale_pt(foldEnd,1.3,foldLineCenter)
            # transfer points to corect data type
            foldStart = (int(Vector2D.pt_x(foldStart)),int(Vector2D.pt_y(foldStart)))
            foldEnd = (int(Vector2D.pt_x(foldEnd)),int(Vector2D.pt_y(foldEnd)))
            
        elif(i == 2):
            #Fold in half again
            show_message("Model verticies " + str(model.polygon_vertices_int()), MsgTypes.info);
            [bl,tl,tr,br] = ([pt for pt in model.polygon_vertices_int()])[0:4]
            foldStart = Vector2D.pt_center(br,tr)
            foldEnd = Vector2D.pt_center(bl,tl)
            # make foldline little bit bigger than conture
            foldLineCenter = Vector2D.pt_center(foldStart,foldEnd)
            foldStart = Vector2D.scale_pt(foldStart,1.2,foldLineCenter)
            foldEnd = Vector2D.scale_pt(foldEnd,1.2,foldLineCenter)
            # transfer points to corect data type
            foldStart = (int(Vector2D.pt_x(foldStart)),int(Vector2D.pt_y(foldStart)))
            foldEnd = (int(Vector2D.pt_x(foldEnd)),int(Vector2D.pt_y(foldEnd)))
            
    elif(TYPE == TEE_SKEL):
        if(i == 1):         
            ls = model.left_shoulder_top()
            lc = model.left_collar()
            lslc = Vector2D.pt_center(ls,lc) # point between ls and lc
            bl = model.bottom_left()
            sbl = Vector2D.translate_pt(bl,Vector2D.pt_diff(lslc,ls)) # shifted bl by vector (ls,lslc)
            foldLineCenter = Vector2D.pt_center(lslc,sbl)
            # make foldline little bit bigger than conture
            lslc = Vector2D.scale_pt(lslc,1.3,foldLineCenter)
            sbl = Vector2D.scale_pt(sbl,1.4,foldLineCenter)
            # transfer points to corect data type
            foldEnd = (int(Vector2D.pt_x(lslc)),int(Vector2D.pt_y(lslc)))
            foldStart = (int(Vector2D.pt_x(sbl)),int(Vector2D.pt_y(sbl)))
        if(i == 2):           
            rs = model.right_shoulder_top()
            rc = model.right_collar()
            rsrc = Vector2D.pt_center(rs,rc) # point between rs and rc
            br = model.bottom_right()
            sbr = Vector2D.translate_pt(br,Vector2D.pt_diff(rsrc,rs)) # shifted br by vector (rs,rsrc)
            foldLineCenter = Vector2D.pt_center(rsrc,sbr)
            # make foldline little bit bigger than conture
            rsrc = Vector2D.scale_pt(rsrc,1.5,foldLineCenter)
            sbr = Vector2D.scale_pt(sbr,1.5,foldLineCenter)
            # transfer points to corect data type
            foldStart = (int(Vector2D.pt_x(rsrc)),int(Vector2D.pt_y(rsrc)))
            foldEnd = (int(Vector2D.pt_x(sbr)),int(Vector2D.pt_y(sbr)))
        if(i == 3):          
            ls = model.left_shoulder_top()
            rs = model.right_shoulder_top()
            bl = model.bottom_left()
            br = model.bottom_right()
            foldStart = Vector2D.pt_center(br,rs)
            foldEnd = Vector2D.pt_center(bl,ls)
            foldLineCenter = Vector2D.pt_center(foldStart,foldEnd)
            # make foldline little bit bigger than conture
            #foldStart = Vector2D.scale_pt(foldStart,0.9,foldLineCenter)
            #foldEnd = Vector2D.scale_pt(foldEnd,0.9,foldLineCenter)
            # transfer points to corect data type
            foldStart = (int(Vector2D.pt_x(foldStart)),int(Vector2D.pt_y(foldStart)))
            foldEnd = (int(Vector2D.pt_x(foldEnd)),int(Vector2D.pt_y(foldEnd)))
            
    else:
        show_message("Not implemented type of cloth",MsgTypes.exception)
        sys.exit()
        
    foldLine = [foldStart, foldEnd]
    show_message("New fold line: " + str(foldLine),MsgTypes.info)
    show_message("GET_FOLD_LINE - end", MsgTypes.debug)
    return foldLine;
 def extract_samples(self,nearest_pts,cv_image,contour):
     [center,b_l,t_l,t_r,b_r] = nearest_pts
     l_line = Vector2D.make_seg(center,t_l)
     r_line = Vector2D.make_seg(center,t_r)
     
     l_side = Vector2D.make_seg(b_l,t_l)
     bl_side = Vector2D.make_seg(b_l,center)
     br_side = Vector2D.make_seg(b_r,center)
     r_side = Vector2D.make_seg(b_r,t_r)
     t_side = Vector2D.make_seg(t_l,t_r)
     l_crop_br = Vector2D.extrapolate_pct(bl_side,0.5)
     l_crop_bl = Vector2D.intercept(l_side,Vector2D.horiz_ln(l_crop_br[1]))
     l_crop_tr = Vector2D.intercept(Vector2D.vert_ln(l_crop_br[0]),l_line)
     l_crop_tl = Vector2D.pt_sum(l_crop_bl,Vector2D.pt_diff(l_crop_tr,l_crop_br))
     l_rect = (l_crop_bl,l_crop_br,l_crop_tr,l_crop_tl)
     r_crop_bl = Vector2D.extrapolate_pct(br_side,0.5)
     r_crop_br = Vector2D.intercept(r_side,Vector2D.horiz_ln(r_crop_bl[1]))
     r_crop_tl = Vector2D.intercept(Vector2D.vert_ln(r_crop_bl[0]),r_line)
     r_crop_tr = Vector2D.pt_sum(r_crop_br,Vector2D.pt_diff(r_crop_tl,r_crop_bl))
     r_rect = (r_crop_bl,r_crop_br,r_crop_tr,r_crop_tl)
     t_crop_bl = Vector2D.extrapolate_pct(l_line,0.5)
     t_crop_br = Vector2D.intercept(Vector2D.horiz_ln(t_crop_bl[1]),r_line)
     if t_l[1] > t_r[1]:
         t_crop_tl = Vector2D.intercept(Vector2D.vert_ln(t_crop_bl[0]),t_side)
         t_crop_tr = Vector2D.pt_sum(t_crop_br,Vector2D.pt_diff(t_crop_tl,t_crop_bl))
     else:
         t_crop_tr = Vector2D.intercept(Vector2D.vert_ln(t_crop_br[0]),t_side)
         t_crop_tl = Vector2D.pt_sum(t_crop_bl,Vector2D.pt_diff(t_crop_tr,t_crop_br))
     
     """
     t_rect_old = (t_crop_bl,t_crop_br,t_crop_tr,t_crop_tl)
     
     (orig_t_width,orig_t_height) = Vector2D.rect_size(t_rect_old)
     while cv.PointPolygonTest(contour,Vector2D.pt_scale(Vector2D.pt_sum(t_crop_tl,t_crop_tr),0.5),0) < 0:
         t_crop_tl = (t_crop_tl[0],t_crop_tl[1]+0.05*orig_t_height)
         t_crop_tr = (t_crop_tr[0],t_crop_tr[1]+0.05*orig_t_height)
         print "shrinking t_height"
     """
     t_rect = (t_crop_bl,t_crop_br,t_crop_tr,t_crop_tl)
     
     (l_width,l_height) = Vector2D.rect_size(l_rect)
     (r_width,r_height) = Vector2D.rect_size(r_rect)
     (t_width,t_height) = Vector2D.rect_size(t_rect)
     #print "Height difference:%f"%(t_height - orig_t_height)
     
     width = min(l_width,r_width,t_width) * 0.9
     height = min(l_height,r_height,t_height) * 0.9
     if width < 5:
         width = 5
         print "Hit min"
     if height < 5:
         height = 5
         print "Hit min"
     l_rect_scaled = Vector2D.scale_rect(l_rect,width,height)
     r_rect_scaled = Vector2D.scale_rect(r_rect,width,height)
     t_rect_scaled = Vector2D.scale_rect(t_rect,width,height)
     filenames = ("l_part.png","r_part.png","t_part.png")
     for i,r in enumerate((l_rect_scaled,r_rect_scaled,t_rect_scaled)):
         
         image_temp = cv.CloneImage(cv_image)
         cv.SetImageROI(image_temp,Vector2D.rect_to_cv(r))
         cv.SaveImage("%s/%s"%(self.save_dir,filenames[i]),image_temp)
     return (l_line,r_line)