forked from ckh08045/AutoPercenty
상세페이지 번역에서 더이상 심플모드 동작하지 않게 수정
옵션페이지에서 심플모드는 옵션5개로 수정하느냐 전체 수정하느냐로 갈림 이미지 번역시 텍스트 삽입부분에 그림자와 배경 추가
This commit is contained in:
parent
ce428b34f2
commit
063b0adbd6
|
|
@ -462,32 +462,32 @@ def modify_detail_page(driver, product_info, gemini, translator, delv_collection
|
|||
naver_code = ""
|
||||
|
||||
|
||||
if not simpleMode: # 심플모드일 경우 네이버 파싱 패스
|
||||
try:
|
||||
logger.debug("네이버쇼핑 파싱 중")
|
||||
products = parse_naver_shopping(product_keyword, naver_code, isOverseas=1, sortcount=5)
|
||||
logger.debug("네이버쇼핑 파싱 완료")
|
||||
# logger.debug(f"네이버 파싱된 상품 리스트 \n {products}")
|
||||
product_info.naver_products = products
|
||||
|
||||
# 네이버 상품가격 담기
|
||||
naver_price = naver_prices(products)
|
||||
# if not simpleMode: # 심플모드일 경우 네이버 파싱 패스
|
||||
try:
|
||||
logger.debug("네이버쇼핑 파싱 중")
|
||||
products = parse_naver_shopping(product_keyword, naver_code, isOverseas=1, sortcount=5)
|
||||
logger.debug("네이버쇼핑 파싱 완료")
|
||||
# logger.debug(f"네이버 파싱된 상품 리스트 \n {products}")
|
||||
product_info.naver_products = products
|
||||
|
||||
# 네이버 상품가격 담기
|
||||
naver_price = naver_prices(products)
|
||||
|
||||
if naver_price[0]: # 리턴값이 있는 경우 사용
|
||||
product_info.naver_low_price = naver_price[0]
|
||||
product_info.naver_avg_price = naver_price[1]
|
||||
product_info.naver_high_price = naver_price[2]
|
||||
else: # 리턴값이 None인 경우 기본값인 100원 사용
|
||||
product_info.naver_low_price = 100
|
||||
product_info.naver_avg_price = 100
|
||||
product_info.naver_high_price = 100
|
||||
if naver_price[0]: # 리턴값이 있는 경우 사용
|
||||
product_info.naver_low_price = naver_price[0]
|
||||
product_info.naver_avg_price = naver_price[1]
|
||||
product_info.naver_high_price = naver_price[2]
|
||||
else: # 리턴값이 None인 경우 기본값인 100원 사용
|
||||
product_info.naver_low_price = 100
|
||||
product_info.naver_avg_price = 100
|
||||
product_info.naver_high_price = 100
|
||||
|
||||
# product_info_text = NS_info(products)
|
||||
product_info_card = NS_info_with_HTML(products)
|
||||
# logger.debug(f"수집된 정보 \n {product_info_card} \n")
|
||||
logger.debug("네이버쇼핑 파싱 완료")
|
||||
except Exception as e:
|
||||
logger.debug(f"네이버쇼핑 파싱 중 에러발생 : {e}", exc_info=True)
|
||||
# product_info_text = NS_info(products)
|
||||
product_info_card = NS_info_with_HTML(products)
|
||||
# logger.debug(f"수집된 정보 \n {product_info_card} \n")
|
||||
logger.debug("네이버쇼핑 파싱 완료")
|
||||
except Exception as e:
|
||||
logger.debug(f"네이버쇼핑 파싱 중 에러발생 : {e}", exc_info=True)
|
||||
|
||||
|
||||
|
||||
|
|
@ -645,19 +645,20 @@ def modify_detail_page(driver, product_info, gemini, translator, delv_collection
|
|||
logger.debug(f"원본 이미지 URLs [{len(detail_images)}]개 수집 완료")
|
||||
# logger.debug(f"detail_images List : {detail_images}")
|
||||
# logger.debug(f"현재 속성값 :{current_value}")
|
||||
if not simpleMode: # 심플모드일 경우 상품카드 작성하지 않음
|
||||
logger.debug("product_info_card 결합.")
|
||||
# info_value = product_info_card + '<br><br>' + cost_add_text + '<br><br>'
|
||||
info_value = product_info_card + '<br><br>' + weight_text + '<br><br>'
|
||||
# textarea.send_keys(product_info_card)
|
||||
time.sleep(0.2)
|
||||
combined_value = info_value
|
||||
# if not simpleMode: # 심플모드일 경우 상품카드 작성하지 않음
|
||||
|
||||
logger.debug(f"{combined_value}")
|
||||
logger.debug("product_info_card 결합.")
|
||||
# info_value = product_info_card + '<br><br>' + cost_add_text + '<br><br>'
|
||||
info_value = product_info_card + '<br><br>' + weight_text + '<br><br>'
|
||||
# textarea.send_keys(product_info_card)
|
||||
time.sleep(0.2)
|
||||
combined_value = info_value
|
||||
|
||||
# # data-value 속성을 새로운 값으로 설정합니다.
|
||||
logger.debug("product_info_card + 기존 내용 입력.")
|
||||
# driver.execute_script("arguments[0].setAttribute('data-value', arguments[1]);", textarea, combined_value)
|
||||
logger.debug(f"{combined_value}")
|
||||
|
||||
# # data-value 속성을 새로운 값으로 설정합니다.
|
||||
logger.debug("product_info_card + 기존 내용 입력.")
|
||||
# driver.execute_script("arguments[0].setAttribute('data-value', arguments[1]);", textarea, combined_value)
|
||||
|
||||
logger.debug("HTML 수정 버튼 다시 클릭하여 기본편집페이지로 돌아감.")
|
||||
click_element(driver, 'XPATH', html_btn_xpath, 5, 'ac')
|
||||
|
|
|
|||
|
|
@ -27,76 +27,9 @@ def inpaint_text(image, detected_texts, expansion=5):
|
|||
|
||||
# 여기에서 딥러닝 기반 인페인팅 모델을 적용할 수 있습니다.
|
||||
# 인페이팅 알고리즘 적용 (TELEA 또는 NS 방식 중 선택)
|
||||
inpainted_image = cv2.inpaint(image, mask, inpaintRadius=3, flags=cv2.INPAINT_TELEA)
|
||||
inpainted_image = cv2.inpaint(image, mask, inpaintRadius=2, flags=cv2.INPAINT_TELEA)
|
||||
|
||||
# 결과 이미지 반환
|
||||
return inpainted_image
|
||||
|
||||
|
||||
def inpaint_text_with_deepfill(image, detected_texts, model_checkpoint, expansion=5):
|
||||
"""
|
||||
이미지 내 텍스트를 제거하기 위해 DeepFill v2 기반의 인페이팅 기법을 사용합니다.
|
||||
이 함수는 detect_text에서 반환된 텍스트 위치와 관련 데이터를 사용하여 인페인팅을 수행합니다.
|
||||
|
||||
Parameters:
|
||||
- image: 인페인팅을 수행할 이미지 (OpenCV 이미지 포맷)
|
||||
- detected_texts: 감지된 텍스트 목록, 각 텍스트는 (box, text, confidence, width, height) 포맷
|
||||
- model_checkpoint: DeepFill v2 모델 체크포인트 경로
|
||||
- expansion: 텍스트 박스 확장 크기 (기본값 5)
|
||||
"""
|
||||
try:
|
||||
# 모델 로드
|
||||
model = InpaintCAModel()
|
||||
model.load_checkpoint(model_checkpoint)
|
||||
logging.info("모델이 성공적으로 로드되었습니다.")
|
||||
|
||||
# 마스크 초기화
|
||||
mask = np.zeros(image.shape[:2], dtype=np.uint8)
|
||||
|
||||
# 감지된 텍스트를 기반으로 마스크 생성
|
||||
for (box, text, confidence, text_width, text_height) in detected_texts:
|
||||
x_min, y_min = np.min(box, axis=0)
|
||||
x_max, y_max = np.max(box, axis=0)
|
||||
|
||||
# 박스 확장
|
||||
x_min = max(x_min - expansion, 0)
|
||||
y_min = max(y_min - expansion, 0)
|
||||
x_max = min(x_max + expansion, image.shape[1])
|
||||
y_max = min(y_max + expansion, image.shape[0])
|
||||
|
||||
cv2.rectangle(mask, (int(x_min), int(y_min)), (int(x_max), int(y_max)), 255, thickness=-1)
|
||||
|
||||
# 이미지와 마스크 정규화
|
||||
image = image / 255.0
|
||||
mask = mask / 255.0
|
||||
|
||||
# 인페인팅 실행
|
||||
inpainted_image = model.test(image, mask)
|
||||
inpainted_image = (inpainted_image * 255).astype(np.uint8)
|
||||
|
||||
logging.info("인페인팅이 성공적으로 완료되었습니다.")
|
||||
return inpainted_image
|
||||
|
||||
except FileNotFoundError as e:
|
||||
logging.error(e)
|
||||
except Exception as e:
|
||||
logging.error(f"인페인팅 과정에서 예상치 못한 오류가 발생했습니다: {e}")
|
||||
return None
|
||||
|
||||
|
||||
|
||||
# # 모델 로드 (예: 모델 파일 경로가 필요함)
|
||||
# model = InpaintCAModel()
|
||||
# model.load_checkpoint(checkpoint_model_path)
|
||||
|
||||
# # 이미지 로드
|
||||
# image = cv2.imread('path_to_your_image.jpg')
|
||||
|
||||
# # 텍스트 위치와 정보 (예시 데이터)
|
||||
# detected_texts = [((50, 50, 150, 100), "Example text", 0.95)]
|
||||
|
||||
# # 인페인팅 실행
|
||||
# inpainted_image = inpaint_text(image, detected_texts, model)
|
||||
|
||||
# # 결과 이미지 저장
|
||||
# cv2.imwrite('inpainted_image.jpg', inpainted_image)
|
||||
|
|
|
|||
|
|
@ -109,17 +109,17 @@ def draw_text_with_border(draw, text, position, font, text_color, border_color):
|
|||
def draw_text_with_effects(draw, text, position, font, text_color="white", border_color="black"):
|
||||
# 그림자 효과
|
||||
shadow_offset = (2, 2)
|
||||
draw.text((position[0] + shadow_offset[0], position[1] + shadow_offset[1]), text, font=font, fill="gray")
|
||||
draw.text((position[0] + shadow_offset[0], position[1] + shadow_offset[1]), text, fill="gray", font=font)
|
||||
|
||||
# 텍스트 테두리
|
||||
offsets = [(-1, -1), (-1, 1), (1, -1), (1, 1), (-1, 0), (1, 0), (0, -1), (0, 1)]
|
||||
for offset in offsets:
|
||||
draw.text((position[0] + offset[0], position[1] + offset[1]), text, font=font, fill=border_color)
|
||||
draw.text((position[0] + offset[0], position[1] + offset[1]), text, fill=border_color, font=font)
|
||||
|
||||
# 본래 텍스트
|
||||
draw.text(position, text, font=font, fill=text_color)
|
||||
|
||||
def draw_translucent_background(draw, box, fill_color=(255, 255, 255, 128)):
|
||||
def draw_translucent_background(draw, box, fill_color=(255, 255, 255, 50)):
|
||||
"""텍스트 주변에 반투명 배경을 추가합니다."""
|
||||
margin = 10 # 배너와 텍스트 사이의 여백
|
||||
expanded_box = [box[0] - margin, box[1] - margin, box[2] + margin, box[3] + margin]
|
||||
|
|
@ -142,8 +142,6 @@ def insert_text(inpainted_image, translated_texts, detected_texts):
|
|||
for detected_text, translated_text in zip(detected_texts, translated_texts):
|
||||
box = detected_text[0] # (box, text, confidence) 형태의 detected_text에서 box를 추출
|
||||
|
||||
box2, _, _, _, _ = detected_text # box 정보 언패킹
|
||||
draw_translucent_background(draw, box)
|
||||
text_position = (box[0], box[1]) # 텍스트 위치 설정
|
||||
|
||||
# box 형태: [[x1, y1], [x2, y2], [x3, y3], [x4, y4]]
|
||||
|
|
@ -153,9 +151,12 @@ def insert_text(inpainted_image, translated_texts, detected_texts):
|
|||
x_min, x_max = min(x_coords), max(x_coords)
|
||||
y_min, y_max = min(y_coords), max(y_coords)
|
||||
|
||||
new_box = [x_min, y_min, x_max, y_max]
|
||||
draw_translucent_background(draw, new_box)
|
||||
|
||||
# 수정된 부분: 올바른 x, y 좌표를 사용하여 dominant_color 계산
|
||||
dominant_color = get_dominant_color(image, (x_min, y_min, x_max, y_max))
|
||||
complementary_color = get_complementary_color(dominant_color)
|
||||
# dominant_color = get_dominant_color(image, (x_min, y_min, x_max, y_max))
|
||||
# complementary_color = get_complementary_color(dominant_color)
|
||||
|
||||
# translated_text = detected_text[1] # 번역된 텍스트
|
||||
print(f"translated_text : {translated_text}")
|
||||
|
|
|
|||
Loading…
Reference in New Issue