if r_name != o_name:
        print 'find a error,idx: ', idx
        continue
    full_img_path = relative_path + r_name
    img = cv2.imread(full_img_path)
    h, w, c = img.shape

    err_1, err_5 = tools.cal_error_nor_diag(
        img, r_, o_)  # r_ have img name , range of [-1,1]  , err_1 is mean
    err_mat.append(err_5)
    out_land = np.array(map(float, o_.split()[1:2 * n_p + 1]))

    if err_1 >= threshold:
        count_drop = count_drop + 1
        draw_img = img.copy()
        draw_img = tools.drawpoints(draw_img, out_land)
        tools.makedir(drop_img_flod)
        draw_img_name = str(err_1) + '_' + r_name
        draw_img_path = drop_img_flod + draw_img_name
        cv2.imwrite(draw_img_path, draw_img)
    else:
        draw_img = img.copy()
        draw_img = tools.drawpoints(draw_img, out_land)
        tools.makedir(draw_img_flod)
        draw_img_name = str(err_1) + '_' + r_name
        draw_img_path = draw_img_flod + draw_img_name
        cv2.imwrite(draw_img_path, draw_img)
# -------------------------------------------------------------- print result
err_mat = np.array(err_mat)
err_mat = np.reshape(err_mat, (-1, 5))
MNE_5 = []
        h1 = (crop_h - 1) / 2
        crop_land = crop_pix_land.copy()
        crop_land[0::2] = (crop_pix_land[0::2] - w1) / w1
        crop_land[1::2] = (crop_pix_land[1::2] - h1) / h1

        # print('crop land ', crop_land)
        # ----------------------------------------------------------- output crop img
        crop_img = img.copy()
        crop_img = crop_img[h_start:h_end + 1, w_start:w_end + 1, :]
        crop_img_name = r_name
        crop_img_path = crop_img_flod + crop_img_name
        tools.makedir(crop_img_flod)
        cv2.imwrite(crop_img_path, crop_img)
        # ----------------------------------------------------------- output crop draw img
        crop_draw_img = crop_img.copy()
        crop_draw_img = tools.drawpoints(crop_draw_img, crop_land)
        crop_draw_img_name = r_name
        crop_draw_img_path = crop_draw_img_flod + crop_draw_img_name
        tools.makedir(crop_draw_img_flod)
        cv2.imwrite(crop_draw_img_path, crop_draw_img)
        # ----------------------------------------------------------- output label
        new_line = r_name
        str_0 = str(crop_land)
        str_1 = str_0.replace("\n", "")
        str_2 = str_1.strip('[]')
        str_3 = str_2.split()
        for i in range(n_p):
            x_ = str_3[2 * i + 0]  # value is [-1,1]
            y_ = str_3[2 * i + 1]

            new_line = new_line + ' ' + str(
	r_name = r_.split()[0]
	o_name = o_.split()[0]
	if r_name != o_name:
		print 'find a error,idx: ', idx 
		continue
	full_img_path = relative_path + r_name
	img = cv2.imread(full_img_path)
	h,w,c = img.shape	

	err_1,err_5 = tools.cal_error_nor_diag(img,r_,o_)	# r_ have img name , range of [-1,1]  err_1 is mean 
	err_mat.append(err_5)
	out_land = np.array(map(float,o_.split()[1:2*n_p+1]))
	if err_1 >= threshold :		
		count_drop = count_drop + 1
		draw_img = img.copy()
		draw_img = tools.drawpoints(draw_img,out_land)
		tools.makedir(drop_img_flod)
		draw_img_name = str(err_1) + '_' + r_name
		draw_img_path = drop_img_flod + draw_img_name
		cv2.imwrite(draw_img_path, draw_img)
	else:
		draw_img = img.copy()
		draw_img = tools.drawpoints(draw_img,out_land)
		tools.makedir(draw_img_flod)
		draw_img_name = str(err_1) + '_' + r_name
		draw_img_path = draw_img_flod + draw_img_name
		cv2.imwrite(draw_img_path, draw_img)
	# print a
# -------------------------------------------------------------- print result
err_mat = np.array(err_mat)
err_mat = np.reshape(err_mat,(-1,5))
		h1 = (crop_h-1)/2
		crop_land = crop_pix_land.copy()
		crop_land[0::2] = (crop_pix_land[0::2] - w1) / w1
		crop_land[1::2] = (crop_pix_land[1::2] - h1) / h1

		# print('crop land ', crop_land)
		# ----------------------------------------------------------- output crop img 
		crop_img = img.copy()
		crop_img = crop_img[h_start:h_end+1,w_start:w_end+1,:]
		crop_img_name = r_name
		crop_img_path = crop_img_flod + crop_img_name
		tools.makedir(crop_img_flod)
		cv2.imwrite(crop_img_path,crop_img)
		# ----------------------------------------------------------- output crop draw img 
		crop_draw_img = crop_img.copy()
		crop_draw_img = tools.drawpoints(crop_draw_img, crop_land)	
		crop_draw_img_name = r_name
		crop_draw_img_path = crop_draw_img_flod + crop_draw_img_name
		tools.makedir(crop_draw_img_flod)
		cv2.imwrite(crop_draw_img_path,crop_draw_img)
		# ----------------------------------------------------------- output label
		new_line = r_name 
		str_0 = str(crop_land)
		str_1 = str_0.replace("\n","")
		str_2 = str_1.strip('[]')
		str_3 = str_2.split()
		for i in range(n_p):
			x_ = str_3[2*i+0] # value is [-1,1] 
			y_ = str_3[2*i+1]

			new_line = new_line + ' ' + str(x_)			# note: the point order has changed: x1,y1,x2...