def query_sub_class(pro_method, image_method, slide_group, is_positive, slide_name): ''' :param pro_method: :param image_method: :param slide_group: :param is_positive: :param slide_name: :return: ''' sub_class = None sql = '''select sub_class from slide_sub_class where pro_method like '%s' and image_method like '%s' and slide_group like '%s' and is_positive like '%s' and slide_name like '%s'; ''' % \ ( pro_method, image_method, slide_group, is_positive, slide_name, ) results = sql_proxy.execute_query(sql) if len(results) > 0: sub_class = results[0][0] return sub_class
def query_all_annos(): ''' 查询所有标注 :return: 返回特定条件下查询标注的id集合 ''' sql = 'select * from annotations' sql_proxy.connect() results = sql_proxy.execute_query(sql) sql_proxy.close() id_list = list() for res in results: uints = res[9].split(';') if len(uints) <= 5: id_list.append(res[0]) return id_list
def query_hard(sid): ''' :param pro_method: :param image_method: :param slide_group: :param is_positive: :param slide_name: :return: ''' is_hard = 'No' sql = '''select * from slide_hard where sid = %d; ''' % \ ( sid ) results = sql_proxy.execute_query(sql) if len(results) > 0: is_hard = 'Yes' return is_hard
def query_annos(sid): ''' 查询切片id = sid 的所有标注 :param sid: 与该标注关联的sid :return: ''' sql = '''select * from annotations where sid = %s;''' % sid annos = list() sql_proxy.connect() results = sql_proxy.execute_query(sql) sql_proxy.close() for res in results: center_point = Point.str_to_Point(res[2]) cir_rect = Rect.str_to_Rect(res[3]) anno_class = res[4] anno_code = res[5] type = res[6] color = res[7] is_typical = res[8] contours = list() uints = res[9].split(';') for uint in uints: if uint == '': continue us = uint.split(',') contours.append([float(us[0]), float(us[1])]) is_hard = res[10] has_contours = res[11] anno = Annotation(center_point, cir_rect, contours, anno_class, anno_code, type, has_contours, color, is_typical) anno.set_is_hard(is_hard) anno.set_aid(res[0]) anno.set_sid(res[1]) annos.append(anno) return annos
from mysql.sql_op import query_slide_info, query_annos, del_anno_by_aid sql_proxy.connect() anno_imgs_path = 'L:/GXB/anno_imgs' # query different group sql = 'select pro_method, image_method, slide_group, is_positive, zoom \ from \ slides \ group by \ pro_method, image_method, slide_group, is_positive \ order by \ pro_method, image_method, slide_group;' slide_batches = sql_proxy.execute_query(sql) log = open(os.path.join(anno_imgs_path, 'log.txt'), 'w') for slide_batch in slide_batches[2:4]: slides = query_slide_info(pro_method=slide_batch[0], image_method=slide_batch[1], slide_group=slide_batch[2], is_positive=slide_batch[3], zoom=slide_batch[4]) print(slide_batch, len(slides)) if len(slides) <= 0: continue slide_reader = srf.get_proxy(slides[0].slide_format()) item = '%s__%s__%s__%s__%s' % (slide_batch[0], slide_batch[1],
def query_slide_info(pro_method='%', image_method='%', slide_group='%', is_positive='%', slide_format='%', slide_name='%', zoom='%'): ''' 查询切片信息,以Slide_List方式返回 :param pro_method: 制片方式 e.g. BD :param image_method: 成像方式 e.g. 3DHistech :param slide_group: 切片批次 e.g. Shengfuyou_1th :param is_positive: 是否阳性 e.g. Yes :param slide_format: 切片格式 e.g. mrxs :param slide_name: 切片名称 e.g. xxxxx.mrxs :param zoom: 切片倍率 e.g. 20x :return: ''' slides_list = list() sql_proxy.connect() # generate sql sql = '''select * from slides where pro_method like '%s' and image_method like '%s' and slide_group like '%s' and is_positive like '%s' and slide_format like '%s' and slide_name like '%s' and zoom like '%s'; ''' %\ ( pro_method, image_method, slide_group, is_positive, slide_format, slide_name, zoom ) slides = sql_proxy.execute_query(sql) # print(len(slides)) for slide in slides: slide_path = slide[1] slide_name = slide[2] slide_group = slide[3] pro_method = slide[4] image_method = slide[5] mpp = slide[6] zoom = slide[7] slide_format = slide[8] format_trans = slide[14] is_positive = slide[9] is_hard = query_hard(slide[0]) width = slide[10] height = slide[11] sub_class = query_sub_class(pro_method, image_method, slide_group, is_positive, slide_name) bounds_x = slide[12] bounds_y = slide[13] modify_info = None file_permission = None md5_info = None slide_info = SlideInfo(slide_path, slide_name, slide_group, pro_method, image_method, mpp, zoom, slide_format, format_trans, is_positive, is_hard, width, height, sub_class, bounds_x, bounds_y, modify_info, file_permission, md5_info) slide_info.set_sid(slide[0]) # slide_info.show_info() slides_list.append(slide_info) sql_proxy.close() return slides_list