鱼C论坛

 找回密码
 立即注册
查看: 872|回复: 3

关于rpc的问题~

[复制链接]
发表于 2020-4-1 10:11:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
xmlrpc.client.Fault: <Fault 1: "<class 'xml.parsers.expat.ExpatError'>:not well-formed (invalid token): line 6, column 89">
有人遇到这种问题嘛~
我把详细代码附在评论区
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-4-1 10:16:07 | 显示全部楼层
服务端:
  1. import cv2
  2. import os
  3. import sys
  4. import numpy as np
  5. import tensorflow as tf

  6. car_plate_w,car_plate_h = 136,36
  7. char_w,char_h = 20,20
  8. char_table = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
  9.               'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '川', '鄂', '赣', '甘', '贵',
  10.               '桂', '黑', '沪', '冀', '津', '京', '吉', '辽', '鲁', '蒙', '闽', '宁', '青', '琼', '陕', '苏', '晋',
  11.               '皖', '湘', '新', '豫', '渝', '粤', '云', '藏', '浙']

  12. def hist_image(img):
  13.     assert img.ndim==2
  14.     hist = [0 for i in range(256)]
  15.     img_h,img_w = img.shape[0],img.shape[1]

  16.     for row in range(img_h):
  17.         for col in range(img_w):
  18.             hist[img[row,col]] += 1
  19.     p = [hist[n]/(img_w*img_h) for n in range(256)]
  20.     p1 = np.cumsum(p)
  21.     for row in range(img_h):
  22.         for col in range(img_w):
  23.             v = img[row,col]
  24.             img[row,col] = p1[v]*255
  25.     return img

  26. def find_board_area(img):
  27.     assert img.ndim==2
  28.     img_h,img_w = img.shape[0],img.shape[1]
  29.     top,bottom,left,right = 0,img_h,0,img_w
  30.     flag = False
  31.     h_proj = [0 for i in range(img_h)]
  32.     v_proj = [0 for i in range(img_w)]

  33.     for row in range(round(img_h*0.5),round(img_h*0.8),3):
  34.         for col in range(img_w):
  35.             if img[row,col]==255:
  36.                 h_proj[row] += 1
  37.         if flag==False and h_proj[row]>12:
  38.             flag = True
  39.             top = row
  40.         if flag==True and row>top+8 and h_proj[row]<12:
  41.             bottom = row
  42.             flag = False

  43.     for col in range(round(img_w*0.3),img_w,1):
  44.         for row in range(top,bottom,1):
  45.             if img[row,col]==255:
  46.                 v_proj[col] += 1
  47.         if flag==False and (v_proj[col]>10 or v_proj[col]-v_proj[col-1]>5):
  48.             left = col
  49.             break
  50.     return left,top,120,bottom-top-10

  51. def verify_scale(rotate_rect):
  52.    error = 0.4
  53.    aspect = 4#4.7272
  54.    min_area = 10*(10*aspect)
  55.    max_area = 150*(150*aspect)
  56.    min_aspect = aspect*(1-error)
  57.    max_aspect = aspect*(1+error)
  58.    theta = 30

  59.    # 宽或高为0,不满足矩形直接返回False
  60.    if rotate_rect[1][0]==0 or rotate_rect[1][1]==0:
  61.        return False

  62.    r = rotate_rect[1][0]/rotate_rect[1][1]
  63.    r = max(r,1/r)
  64.    area = rotate_rect[1][0]*rotate_rect[1][1]
  65.    if area>min_area and area<max_area and r>min_aspect and r<max_aspect:
  66.        # 矩形的倾斜角度在不超过theta
  67.        if ((rotate_rect[1][0] < rotate_rect[1][1] and rotate_rect[2] >= -90 and rotate_rect[2] < -(90 - theta)) or
  68.                (rotate_rect[1][1] < rotate_rect[1][0] and rotate_rect[2] > -theta and rotate_rect[2] <= 0)):
  69.            return True
  70.    return False

  71. def img_Transform(car_rect,image):
  72.     img_h,img_w = image.shape[:2]
  73.     rect_w,rect_h = car_rect[1][0],car_rect[1][1]
  74.     angle = car_rect[2]

  75.     return_flag = False
  76.     if car_rect[2]==0:
  77.         return_flag = True
  78.     if car_rect[2]==-90 and rect_w<rect_h:
  79.         rect_w, rect_h = rect_h, rect_w
  80.         return_flag = True
  81.     if return_flag:
  82.         car_img = image[int(car_rect[0][1]-rect_h/2):int(car_rect[0][1]+rect_h/2),
  83.                   int(car_rect[0][0]-rect_w/2):int(car_rect[0][0]+rect_w/2)]
  84.         return car_img

  85.     car_rect = (car_rect[0],(rect_w,rect_h),angle)
  86.     box = cv2.boxPoints(car_rect)

  87.     heigth_point = right_point = [0,0]
  88.     left_point = low_point = [car_rect[0][0], car_rect[0][1]]
  89.     for point in box:
  90.         if left_point[0] > point[0]:
  91.             left_point = point
  92.         if low_point[1] > point[1]:
  93.             low_point = point
  94.         if heigth_point[1] < point[1]:
  95.             heigth_point = point
  96.         if right_point[0] < point[0]:
  97.             right_point = point

  98.     if left_point[1] <= right_point[1]:  # 正角度
  99.         new_right_point = [right_point[0], heigth_point[1]]
  100.         pts1 = np.float32([left_point, heigth_point, right_point])
  101.         pts2 = np.float32([left_point, heigth_point, new_right_point])  # 字符只是高度需要改变
  102.         M = cv2.getAffineTransform(pts1, pts2)
  103.         dst = cv2.warpAffine(image, M, (round(img_w*2), round(img_h*2)))
  104.         car_img = dst[int(left_point[1]):int(heigth_point[1]), int(left_point[0]):int(new_right_point[0])]

  105.     elif left_point[1] > right_point[1]:  # 负角度
  106.         new_left_point = [left_point[0], heigth_point[1]]
  107.         pts1 = np.float32([left_point, heigth_point, right_point])
  108.         pts2 = np.float32([new_left_point, heigth_point, right_point])  # 字符只是高度需要改变
  109.         M = cv2.getAffineTransform(pts1, pts2)
  110.         dst = cv2.warpAffine(image, M, (round(img_w*2), round(img_h*2)))
  111.         car_img = dst[int(right_point[1]):int(heigth_point[1]), int(new_left_point[0]):int(right_point[0])]

  112.     return car_img

  113. def pre_process(orig_img):

  114.     gray_img = cv2.cvtColor(orig_img, cv2.COLOR_BGR2GRAY)
  115.     # cv2.imshow('gray_img', gray_img)
  116.     # cv2.waitKey(0)

  117.     blur_img = cv2.blur(gray_img, (3, 3))
  118.     # cv2.imshow('blur', blur_img)
  119.     # cv2.waitKey(0)

  120.     sobel_img = cv2.Sobel(blur_img, cv2.CV_16S, 1, 0, ksize=3)
  121.     sobel_img = cv2.convertScaleAbs(sobel_img)
  122.     # cv2.imshow('sobel', sobel_img)
  123.     # cv2.waitKey(0)

  124.     hsv_img = cv2.cvtColor(orig_img, cv2.COLOR_BGR2HSV)
  125.     # cv2.imshow('hsv', hsv_img)
  126.     # cv2.waitKey(0)

  127.     h, s, v = hsv_img[:, :, 0], hsv_img[:, :, 1], hsv_img[:, :, 2]
  128.     # 黄色色调区间[26,34],蓝色色调区间:[100,124]
  129.     blue_img = (((h > 26) & (h < 34)) | ((h > 100) & (h < 124))) & (s > 70) & (v > 70)
  130.     blue_img = blue_img.astype('float32')
  131.     # cv2.imshow('blue', blue_img)
  132.     # cv2.waitKey(0)

  133.     mix_img = np.multiply(sobel_img, blue_img)
  134.     # cv2.imshow('mix', mix_img)
  135.     # cv2.waitKey(0)


  136.     mix_img = mix_img.astype(np.uint8)

  137.     ret, binary_img = cv2.threshold(mix_img, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
  138.     # cv2.imshow('binary',binary_img)
  139.     # cv2.waitKey(0)

  140.     kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(21,5))
  141.     close_img = cv2.morphologyEx(binary_img, cv2.MORPH_CLOSE, kernel)
  142.     # cv2.imshow('close', close_img)
  143.     # cv2.waitKey(0)

  144.     return close_img

  145. # 给候选车牌区域做漫水填充算法,一方面补全上一步求轮廓可能存在轮廓歪曲的问题,
  146. # 另一方面也可以将非车牌区排除掉
  147. def verify_color(rotate_rect,src_image):
  148.     img_h,img_w = src_image.shape[:2]
  149.     mask = np.zeros(shape=[img_h+2,img_w+2],dtype=np.uint8)
  150.     connectivity = 4 #种子点上下左右4邻域与种子颜色值在[loDiff,upDiff]的被涂成new_value,也可设置8邻域
  151.     loDiff,upDiff = 30,30
  152.     new_value = 255
  153.     flags = connectivity
  154.     flags |= cv2.FLOODFILL_FIXED_RANGE  #考虑当前像素与种子象素之间的差,不设置的话则和邻域像素比较
  155.     flags |= new_value << 8
  156.     flags |= cv2.FLOODFILL_MASK_ONLY #设置这个标识符则不会去填充改变原始图像,而是去填充掩模图像(mask)

  157.     rand_seed_num = 5000 #生成多个随机种子
  158.     valid_seed_num = 200 #从rand_seed_num中随机挑选valid_seed_num个有效种子
  159.     adjust_param = 0.1
  160.     box_points = cv2.boxPoints(rotate_rect)
  161.     box_points_x = [n[0] for n in box_points]
  162.     box_points_x.sort(reverse=False)
  163.     adjust_x = int((box_points_x[2]-box_points_x[1])*adjust_param)
  164.     col_range = [box_points_x[1]+adjust_x,box_points_x[2]-adjust_x]
  165.     box_points_y = [n[1] for n in box_points]
  166.     box_points_y.sort(reverse=False)
  167.     adjust_y = int((box_points_y[2]-box_points_y[1])*adjust_param)
  168.     row_range = [box_points_y[1]+adjust_y, box_points_y[2]-adjust_y]
  169.     # 如果以上方法种子点在水平或垂直方向可移动的范围很小,则采用旋转矩阵对角线来设置随机种子点
  170.     if (col_range[1]-col_range[0])/(box_points_x[3]-box_points_x[0])<0.4\
  171.         or (row_range[1]-row_range[0])/(box_points_y[3]-box_points_y[0])<0.4:
  172.         points_row = []
  173.         points_col = []
  174.         for i in range(2):
  175.             pt1,pt2 = box_points[i],box_points[i+2]
  176.             x_adjust,y_adjust = int(adjust_param*(abs(pt1[0]-pt2[0]))),int(adjust_param*(abs(pt1[1]-pt2[1])))
  177.             if (pt1[0] <= pt2[0]):
  178.                 pt1[0], pt2[0] = pt1[0] + x_adjust, pt2[0] - x_adjust
  179.             else:
  180.                 pt1[0], pt2[0] = pt1[0] - x_adjust, pt2[0] + x_adjust
  181.             if (pt1[1] <= pt2[1]):
  182.                 pt1[1], pt2[1] = pt1[1] + adjust_y, pt2[1] - adjust_y
  183.             else:
  184.                 pt1[1], pt2[1] = pt1[1] - y_adjust, pt2[1] + y_adjust
  185.             temp_list_x = [int(x) for x in np.linspace(pt1[0],pt2[0],int(rand_seed_num /2))]
  186.             temp_list_y = [int(y) for y in np.linspace(pt1[1],pt2[1],int(rand_seed_num /2))]
  187.             points_col.extend(temp_list_x)
  188.             points_row.extend(temp_list_y)
  189.     else:
  190.         points_row = np.random.randint(row_range[0],row_range[1],size=rand_seed_num)
  191.         points_col = np.linspace(col_range[0],col_range[1],num=rand_seed_num).astype(np.int)

  192.     points_row = np.array(points_row)
  193.     points_col = np.array(points_col)
  194.     hsv_img = cv2.cvtColor(src_image, cv2.COLOR_BGR2HSV)
  195.     h,s,v = hsv_img[:,:,0],hsv_img[:,:,1],hsv_img[:,:,2]
  196.     # 将随机生成的多个种子依次做漫水填充,理想情况是整个车牌被填充
  197.     flood_img = src_image.copy()
  198.     seed_cnt = 0
  199.     for i in range(rand_seed_num):
  200.         rand_index = np.random.choice(rand_seed_num,1,replace=False)
  201.         row,col = points_row[rand_index],points_col[rand_index]
  202.         # 限制随机种子必须是车牌背景色
  203.         if (((h[row,col]>26)&(h[row,col]<34))|((h[row,col]>100)&(h[row,col]<124)))&(s[row,col]>70)&(v[row,col]>70):
  204.             cv2.floodFill(src_image, mask, (col,row), (255, 255, 255), (loDiff,) * 3, (upDiff,) * 3, flags)
  205.             cv2.circle(flood_img,center=(col,row),radius=2,color=(0,0,255),thickness=2)
  206.             seed_cnt += 1
  207.             if seed_cnt >= valid_seed_num:
  208.                 break
  209.     #======================调试用======================#
  210.     show_seed = np.random.uniform(1,100,1).astype(np.uint16)
  211.     cv2.imshow('floodfill'+str(show_seed),flood_img)
  212.     cv2.imshow('flood_mask'+str(show_seed),mask)
  213.     #======================调试用======================#
  214.     # 获取掩模上被填充点的像素点,并求点集的最小外接矩形
  215.     mask_points = []
  216.     for row in range(1,img_h+1):
  217.         for col in range(1,img_w+1):
  218.             if mask[row,col] != 0:
  219.                 mask_points.append((col-1,row-1))
  220.     mask_rotateRect = cv2.minAreaRect(np.array(mask_points))
  221.     if verify_scale(mask_rotateRect):
  222.         return True,mask_rotateRect
  223.     else:
  224.         return False,mask_rotateRect

  225. # 车牌定位
  226. def locate_carPlate(orig_img,pred_image):
  227.     carPlate_list = []
  228.     temp1_orig_img = orig_img.copy() #调试用
  229.     temp2_orig_img = orig_img.copy() #调试用
  230.     cloneImg,contours,heriachy = cv2.findContours(pred_image,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
  231.     for i,contour in enumerate(contours):
  232.         cv2.drawContours(temp1_orig_img, contours, i, (0, 255, 255), 2)
  233.         # 获取轮廓最小外接矩形,返回值rotate_rect
  234.         rotate_rect = cv2.minAreaRect(contour)
  235.         # 根据矩形面积大小和长宽比判断是否是车牌
  236.         if verify_scale(rotate_rect):
  237.             ret,rotate_rect2 = verify_color(rotate_rect,temp2_orig_img)
  238.             if ret == False:
  239.                 continue
  240.             # 车牌位置矫正
  241.             car_plate = img_Transform(rotate_rect2, temp2_orig_img)
  242.             car_plate = cv2.resize(car_plate,(car_plate_w,car_plate_h)) #调整尺寸为后面CNN车牌识别做准备
  243.             #========================调试看效果========================#
  244.             box = cv2.boxPoints(rotate_rect2)
  245.             for k in range(4):
  246.                 n1,n2 = k%4,(k+1)%4
  247.                 cv2.line(temp1_orig_img,(box[n1][0],box[n1][1]),(box[n2][0],box[n2][1]),(255,0,0),2)
  248.             cv2.imshow('opencv_' + str(i), car_plate)
  249.             #========================调试看效果========================#
  250.             carPlate_list.append(car_plate)

  251.     cv2.imshow('contour', temp1_orig_img)
  252.     return carPlate_list

  253. # 左右切割
  254. def horizontal_cut_chars(plate):
  255.     char_addr_list = []
  256.     area_left,area_right,char_left,char_right= 0,0,0,0
  257.     img_w = plate.shape[1]

  258.     # 获取车牌每列边缘像素点个数
  259.     def getColSum(img,col):
  260.         sum = 0
  261.         for i in range(img.shape[0]):
  262.             sum += round(img[i,col]/255)
  263.         return sum;

  264.     sum = 0
  265.     for col in range(img_w):
  266.         sum += getColSum(plate,col)
  267.     # 每列边缘像素点必须超过均值的60%才能判断属于字符区域
  268.     col_limit = 0#round(0.5*sum/img_w)
  269.     # 每个字符宽度也进行限制
  270.     charWid_limit = [round(img_w/12),round(img_w/5)]
  271.     is_char_flag = False

  272.     for i in range(img_w):
  273.         colValue = getColSum(plate,i)
  274.         if colValue > col_limit:
  275.             if is_char_flag == False:
  276.                 area_right = round((i+char_right)/2)
  277.                 area_width = area_right-area_left
  278.                 char_width = char_right-char_left
  279.                 if (area_width>charWid_limit[0]) and (area_width<charWid_limit[1]):
  280.                     char_addr_list.append((area_left,area_right,char_width))
  281.                 char_left = i
  282.                 area_left = round((char_left+char_right) / 2)
  283.                 is_char_flag = True
  284.         else:
  285.             if is_char_flag == True:
  286.                 char_right = i-1
  287.                 is_char_flag = False
  288.     # 手动结束最后未完成的字符分割
  289.     if area_right < char_left:
  290.         area_right,char_right = img_w,img_w
  291.         area_width = area_right - area_left
  292.         char_width = char_right - char_left
  293.         if (area_width > charWid_limit[0]) and (area_width < charWid_limit[1]):
  294.             char_addr_list.append((area_left, area_right, char_width))
  295.     return char_addr_list

  296. def get_chars(car_plate):
  297.     img_h,img_w = car_plate.shape[:2]
  298.     h_proj_list = [] # 水平投影长度列表
  299.     h_temp_len,v_temp_len = 0,0
  300.     h_startIndex,h_end_index = 0,0 # 水平投影记索引
  301.     h_proj_limit = [0.2,0.8] # 车牌在水平方向得轮廓长度少于20%或多余80%过滤掉
  302.     char_imgs = []

  303.     # 将二值化的车牌水平投影到Y轴,计算投影后的连续长度,连续投影长度可能不止一段
  304.     h_count = [0 for i in range(img_h)]
  305.     for row in range(img_h):
  306.         temp_cnt = 0
  307.         for col in range(img_w):
  308.             if car_plate[row,col] == 255:
  309.                 temp_cnt += 1
  310.         h_count[row] = temp_cnt
  311.         if temp_cnt/img_w<h_proj_limit[0] or temp_cnt/img_w>h_proj_limit[1]:
  312.             if h_temp_len != 0:
  313.                 h_end_index = row-1
  314.                 h_proj_list.append((h_startIndex,h_end_index))
  315.                 h_temp_len = 0
  316.             continue
  317.         if temp_cnt > 0:
  318.             if h_temp_len == 0:
  319.                 h_startIndex = row
  320.                 h_temp_len = 1
  321.             else:
  322.                 h_temp_len += 1
  323.         else:
  324.             if h_temp_len > 0:
  325.                 h_end_index = row-1
  326.                 h_proj_list.append((h_startIndex,h_end_index))
  327.                 h_temp_len = 0

  328.     # 手动结束最后得水平投影长度累加
  329.     if h_temp_len != 0:
  330.         h_end_index = img_h-1
  331.         h_proj_list.append((h_startIndex, h_end_index))
  332.     # 选出最长的投影,该投影长度占整个截取车牌高度的比值必须大于0.5
  333.     h_maxIndex,h_maxHeight = 0,0
  334.     for i,(start,end) in enumerate(h_proj_list):
  335.         if h_maxHeight < (end-start):
  336.             h_maxHeight = (end-start)
  337.             h_maxIndex = i
  338.     if h_maxHeight/img_h < 0.5:
  339.         return char_imgs
  340.     chars_top,chars_bottom = h_proj_list[h_maxIndex][0],h_proj_list[h_maxIndex][1]

  341.     plates = car_plate[chars_top:chars_bottom+1,:]
  342.     cv2.imwrite('carIdentityData/opencv_output/car.jpg', car_plate)
  343.     cv2.imwrite('carIdentityData/opencv_output/plate.jpg', plates)
  344.     char_addr_list = horizontal_cut_chars(plates)

  345.     for i,addr in enumerate(char_addr_list):
  346.         char_img = car_plate[chars_top:chars_bottom+1,addr[0]:addr[1]]
  347.         char_img = cv2.resize(char_img,(char_w,char_h))
  348.         char_imgs.append(char_img)
  349.     return char_imgs

  350. def extract_char(car_plate):
  351.     gray_plate = cv2.cvtColor(car_plate,cv2.COLOR_BGR2GRAY)
  352.     ret,binary_plate = cv2.threshold(gray_plate,0,255,cv2.THRESH_BINARY|cv2.THRESH_OTSU)
  353.     char_img_list = get_chars(binary_plate)
  354.     return char_img_list

  355. def cnn_select_carPlate(plate_list,model_path):
  356.     if len(plate_list) == 0:
  357.         return False,plate_list
  358.     g1 = tf.Graph()
  359.     sess1 = tf.Session(graph=g1)
  360.     with sess1.as_default():
  361.         with sess1.graph.as_default():
  362.             model_dir = os.path.dirname(model_path)
  363.             saver = tf.train.import_meta_graph(model_path)
  364.             saver.restore(sess1, tf.train.latest_checkpoint(model_dir))
  365.             graph = tf.get_default_graph()
  366.             net1_x_place = graph.get_tensor_by_name('x_place:0')
  367.             net1_keep_place = graph.get_tensor_by_name('keep_place:0')
  368.             net1_out = graph.get_tensor_by_name('out_put:0')

  369.             input_x = np.array(plate_list)
  370.             net_outs = tf.nn.softmax(net1_out)
  371.             preds = tf.argmax(net_outs,1) #预测结果
  372.             probs = tf.reduce_max(net_outs,reduction_indices=[1]) #结果概率值
  373.             pred_list,prob_list = sess1.run([preds,probs],feed_dict={net1_x_place:input_x,net1_keep_place:1.0})
  374.             # 选出概率最大的车牌
  375.             result_index,result_prob = -1,0.
  376.             for i,pred in enumerate(pred_list):
  377.                 if pred==1 and prob_list[i]>result_prob:
  378.                     result_index,result_prob = i,prob_list[i]
  379.             if result_index == -1:
  380.                 return False,plate_list[0]
  381.             else:
  382.                 return True,plate_list[result_index]

  383. def cnn_recongnize_char(img_list,model_path):
  384.     g2 = tf.Graph()
  385.     sess2 = tf.Session(graph=g2)
  386.     text_list = []
  387.     pro_list = []

  388.     if len(img_list) == 0:
  389.         return text_list
  390.     with sess2.as_default():
  391.         with sess2.graph.as_default():
  392.             model_dir = os.path.dirname(model_path)
  393.             saver = tf.train.import_meta_graph(model_path)
  394.             saver.restore(sess2, tf.train.latest_checkpoint(model_dir))
  395.             graph = tf.get_default_graph()
  396.             net2_x_place = graph.get_tensor_by_name('x_place:0')
  397.             net2_keep_place = graph.get_tensor_by_name('keep_place:0')
  398.             net2_out = graph.get_tensor_by_name('out_put:0')

  399.             data = np.array(img_list)
  400.             # 数字、字母、汉字,从67维向量找到概率最大的作为预测结果
  401.             net_out = tf.nn.softmax(net2_out)
  402.             preds = tf.argmax(net_out,1)
  403.             probs = tf.reduce_max(net_out, reduction_indices=[1])  # 结果概率值
  404.             my_preds,my_probs= sess2.run([preds,probs], feed_dict={net2_x_place: data, net2_keep_place: 1.0})
  405.             # print(my_preds)
  406.             print(my_probs)
  407.             for i in my_preds:
  408.                 text_list.append(char_table[i])
  409.             prob = 0
  410.             for i in my_probs:
  411.                 prob = prob + i
  412.             prob=prob/len(my_probs)
  413.             return text_list,prob

  414. # if __name__ == '__main__':
  415. #     cur_dir = sys.path[0]
  416. #     car_plate_w,car_plate_h = 136,36
  417. #     char_w,char_h = 20,20
  418. #     plate_model_path = os.path.join(cur_dir, './carIdentityData/model/plate_recongnize/model.ckpt-510.meta')
  419. #     char_model_path = os.path.join(cur_dir,'./carIdentityData/model/char_recongnize/model.ckpt-520.meta')
  420. #     img = cv2.imread('carIdentityData/images/43.jpg')
  421. #
  422. #     # 预处理
  423. #     pred_img = pre_process(img)
  424. #     # cv2.imshow('pred_img', pred_img)
  425. #     # cv2.waitKey(0)
  426. #
  427. #     # 车牌定位
  428. #     car_plate_list = locate_carPlate(img,pred_img)
  429. #
  430. #     # CNN车牌过滤
  431. #     ret,car_plate = cnn_select_carPlate(car_plate_list,plate_model_path)
  432. #     if ret == False:
  433. #         print("未检测到车牌")
  434. #         sys.exit(-1)
  435. #     # cv2.imshow('cnn_plate',car_plate)
  436. #     # cv2.waitKey(0)
  437. #
  438. #     # 字符提取
  439. #     char_img_list = extract_char(car_plate)
  440. #     print(len(char_img_list))
  441. #     # CNN字符识别
  442. #     text,pro = cnn_recongnize_char(char_img_list,char_model_path)
  443. #     print(text)
  444. #     print(pro)
  445. def recognizePlatestr(src):
  446.     cur_dir = sys.path[0]
  447.     car_plate_w,car_plate_h = 136,36
  448.     char_w,char_h = 20,20
  449.     plate_model_path = os.path.join(cur_dir, './carIdentityData/model/plate_recongnize/model.ckpt-510.meta')
  450.     char_model_path = os.path.join(cur_dir,'./carIdentityData/model/char_recongnize/model.ckpt-520.meta')
  451.     # img = cv2.imread('./carIdentityData/images/32.jpg')
  452.     img = cv2.imread(src)

  453.     # 预处理
  454.     pred_img = pre_process(img)
  455.     # cv2.imshow('pred_img', pred_img)
  456.     # cv2.waitKey(0)

  457.     # 车牌定位
  458.     car_plate_list = locate_carPlate(img,pred_img)

  459.     # CNN车牌过滤
  460.     ret,car_plate = cnn_select_carPlate(car_plate_list,plate_model_path)
  461.     if ret == False:
  462.         print("未检测到车牌")
  463.         sys.exit(-1)
  464.     # 字符提取
  465.     char_img_list = extract_char(car_plate)
  466.     print(len(char_img_list))
  467.     # CNN字符识别
  468.     text,confidence = cnn_recongnize_char(char_img_list,char_model_path)
  469.     confidence = str(round(confidence, 3))
  470.     str1 = ''.join(text)
  471.     laststr = str1 + "#" + confidence
  472.     return laststr

  473. from xmlrpc.server import SimpleXMLRPCServer
  474. server = SimpleXMLRPCServer(('localhost', 8888)) # 初始化
  475. server.register_function(recognizePlatestr, "get_platestr") # 注册函数
  476. print ("Listening for Client")
  477. server.serve_forever() # 保持等待调用状态
复制代码


客户端:
  1. from xmlrpc.client import ServerProxy

  2. server = ServerProxy("http://localhost:8888") # 初始化服务器
  3. path = 'D:\pycharm\djangocode\project6\myApp\plateRecognize\carIdentityData\images\23.jpg'
  4. print(server.get_platestr(path))
  5. platestr=server.get_platestr(path)
  6. print("222")
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-1 10:20:34 From FishC Mobile | 显示全部楼层
愿你 发表于 2020-4-1 10:16
服务端:

客户端:

好长……
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-1 10:26:23 | 显示全部楼层

服务端只要看最后那几行就好了~
我单在文件里独运行那个recognizePlatestr,是能够有结果的。
如下:
  1. str = recognizePlatestr('./carIdentityData/images/23.jpg')
  2. print(str)
复制代码


但是我远程调用就不行了 不知道为什么
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-19 11:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表