<jupyter_start><jupyter_text>bbox가 남아있는 사진만 남기기<jupyter_code># os.remove('bbox1.txt')
os.chdir('../test')
file_list=glob('../label_gorani/*.txt')
print(len(file_list))
print(type(file_list))
print(file_list[0:3])
file_list2=[]
for i in range(len(file_list)):
    file_list2.append(file_list[i][16:-3]+'jpg')
print(file_list2[0:3])
os.getcwd()
os.chdir('../image_gorani')
os.getcwd()
file_list_image=glob('*.jpg')
print(len(file_list_image))
print(type(file_list_image))
print(file_list_image[0:3])
for i in range(len(file_list_image)):
    if file_list_image[i] not in file_list2:
        os.remove(file_list_image[i])<jupyter_output><empty_output><jupyter_text>사진의 bbox표시 띄우기  파일 목록 불러오기<jupyter_code>import cv2
import sys
from glob import glob
import numpy as np 
jpg_list=glob('../image_wildboar/*.jpg')
print(len(jpg_list))
print(type(jpg_list))
print(jpg_list[0:2])
for i in range(len(jpg_list)):
    jpg_list[i]=jpg_list[i].replace('\\','/')
jpg_list[0:3]
jpg_list[4522][18:-4]
import os
os.getcwd()
os.chdir('../test')
jpg_list[0][16:]
jpg_list[150]
jpg_list[150][16:-4]
import os
os.getcwd()<jupyter_output><empty_output><jupyter_text>사진 샘플 띄워보기<jupyter_code>#practice MegaDetector
i=4522
img_array = np.fromfile('../image_wildboar/'+jpg_list[i][18:], np.uint8) # 한글제목을 불러오기 위한 디코딩
img = cv2.imdecode(img_array, cv2.IMREAD_COLOR)
fy, fx, _ = img.shape # 사진 크기값 받아오기
x,y,w,h = 0.4747, 0.2639, 0.4307, 0.4169
x1=round(x*fx)
x2=round((x+w)*fx)
y1=round(y*fy)
y2=round((y+h)*fy)
# cv2.rectangle(img, (x1,y1), (x2,y2), (0,0,255),5)
cv2.imshow(str(i), img)
cv2.waitKey()
cv2.destroyAllWindows()
#practice YOLOv5
i=4522 
img_array = np.fromfile('../image_wildboar/'+jpg_list[i][18:], np.uint8) # 한글제목을 불러오기 위한 디코딩
img = cv2.imdecode(img_array, cv2.IMREAD_COLOR)
fy, fx, _ = img.shape # 사진 크기값 받아오기
x,y,w,h = 0.4747, 0.2639, 0.4307, 0.4169
x1=round((x-0.5*w)*fx)
x2=round((x+0.5*w)*fx)
y1=round((y-0.5*h)*fy)
y2=round((y+0.5*h)*fy)
cv2.rectangle(img, (x1,y1), (x2,y2), (0,0,255),5)
cv2.imshow(str(i), img)
cv2.waitKey()
cv2.destroyAllWindows()
#practice YOLOv5 좌표얻기
i=4522 
img_array = np.fromfile('../image_wildboar/'+jpg_list[i][18:], np.uint8) # 한글제목을 불러오기 위한 디코딩
img = cv2.imdecode(img_array, cv2.IMREAD_COLOR)
fy, fx, _ = img.shape # 사진 크기값 받아오기
x,y,w,h = 0.4747, 0.2639, 0.4307, 0.4169
x1=round(x*fx)
x2=round((x+w)*fx)
y1=round(y*fy)
y2=round((y+h)*fy)
x=(x2+x1)/(2*fx)
y=(y2+y1)/(2*fy)
w=(x2-x1)/fx
h=(y2-y1)/fy
print(x,y,w,h)
#practice YOLOv5
i=4522 
img_array = np.fromfile('../image_wildboar/'+jpg_list[i][18:], np.uint8) # 한글제목을 불러오기 위한 디코딩
img = cv2.imdecode(img_array, cv2.IMREAD_COLOR)
fy, fx, _ = img.shape # 사진 크기값 받아오기
x,y,w,h = 0.6902, 0.4722, 0.4305, 0.4167
x1=round((x-0.5*w)*fx)
x2=round((x+0.5*w)*fx)
y1=round((y-0.5*h)*fy)
y2=round((y+0.5*h)*fy)
cv2.rectangle(img, (x1,y1), (x2,y2), (0,0,255),5)
cv2.imshow(str(i), img)
cv2.moveWindow(str(i),-16,-31)
cv2.waitKey()
cv2.destroyAllWindows()
#practice
i=4522
img_array = np.fromfile('../image_wildboar/'+jpg_list[i][18:], np.uint8)
img = cv2.imdecode(img_array, cv2.IMREAD_COLOR)
fy, fx, _ = img.shape
with open('../label_wildboar/'+jpg_list[i][18:-4]+'.txt', 'r') as f:
    code=f.read().split('\n')
for j in range(len(code)):
    _,x,y,w,h=code[j].split(' ')
    x=float(x); y=float(y); w=float(w); h=float(h)
    x1=round(-fx/2*w+fx*x)
    x2=round(fx/2*w+fx*x)
    y1=round(-fy/2*h+fy*y)
    y2=round(fy/2*h+fy*y)
    w=x2-x1
    h=y2-y1
    cv2.rectangle(img, (x1,y1), (x2,y2), (0,0,255),5)
#     _,x,y,w,h=f.read().split(' ')
# x=float(x); y=float(y); w=float(w); h=float(h)
# x1=round(-fx/2*w+fx*x)
# x2=round(fx/2*w+fx*x)
# y1=round(-fy/2*h+fy*y)
# y2=round(fy/2*h+fy*y)
# cv2.rectangle(img, (x1,y1), (x2,y2), (0,0,255),5)
cv2.imshow(str(i), img)
cv2.waitKey()
cv2.destroyAllWindows()
# real
# esc를 누르면 다음사진
# r을 누르면 이상한 사진목록 세이브
# q를 누르면 종료
strange_list=[]
start=1448
for i in range(start,len(jpg_list)):
    img_array = np.fromfile(jpg_list[i], np.uint8)
    img = cv2.imdecode(img_array, cv2.IMREAD_COLOR)
    fy, fx, _ = img.shape
    with open('../label_reformat_real/'+jpg_list[i][9:-4]+'.txt', 'r') as f:
        code=f.read().split('\n')
    for j in range(len(code)):
        _,x,y,w,h=code[j].split(' ')
        x=float(x); y=float(y); w=float(w); h=float(h)
        x1=round(-fx/2*w+fx*x)
        x2=round(fx/2*w+fx*x)
        y1=round(-fy/2*h+fy*y)
        y2=round(fy/2*h+fy*y)
        cv2.rectangle(img, (x1,y1), (x2,y2), (0,0,255),5)
    cv2.imshow(str(i), img)
    cv2.moveWindow(str(i),-16,-31) # 창 위치 조절
    key=cv2.waitKey()
    if key == ord('q'):
        break
    elif key == ord('r'):
        strange_list.append(jpg_list[i][9:-4]+'.jpg')
    cv2.destroyAllWindows()
cv2.destroyAllWindows()
print(jpg_list[i][9:-4],'.jpg 까지 확인하였습니다.')
print(jpg_list[i][9:-4], f'.jpg 는 {i}번째이므로 다음에 돌리면 start값을 {i+1}로 주세요')
strange_list[-4:]
s=''
for i in range(len(strange_list)):
    s+=strange_list[i]
    s+='\n'
with open('strange.txt', 'a') as f:
    f.write(s)
# sample
# p를 누르면 다음사진 | press 'p' means show next sccne
# b를 누르면 이전사진 | press 'b' means show before scene
# r을 누르면 이상한 사진목록 세이브 | press 'r' means record strange scene name
# q를 누르면 종료 | press 'q' means quit system
start=4522
strange_list=[]
i=start
while i<len(jpg_list):
    img_array = np.fromfile(jpg_list[i], np.uint8)
    img = cv2.imdecode(img_array, cv2.IMREAD_COLOR)
    fy, fx, _ = img.shape
    with open('../label_wildboar/'+jpg_list[i][18:-4]+'.txt', 'r') as f:
        code=f.read().split('\n')
    for j in range(len(code)):
        _,x,y,w,h=code[j].split(' ')
        x=float(x); y=float(y); w=float(w); h=float(h)
        x1=round(fx*(x-w))
        x2=round(fx*x)
        y1=round(fy*(y-h))
        y2=round(fy*y)
        cv2.rectangle(img, (x1,y1), (x2,y2), (0,0,255),5)
    cv2.imshow(str(i), img)
    cv2.moveWindow(str(i),-16,-31) # 창 위치 조절
    key=cv2.waitKey()
    if key == ord('q'):
        break
    if key == ord('r'):
        strange_list.append(jpg_list[i][18:-4]+'.jpg')
        i+=1
        cv2.destroyAllWindows()
    if key == ord('p'):
        i+=1
        cv2.destroyAllWindows()
    if key == ord('b'):
        i-=1
        cv2.destroyAllWindows()
    cv2.destroyAllWindows()
cv2.destroyAllWindows()
print(jpg_list[i][18:-4],'.jpg 까지 확인하였습니다.')
print(jpg_list[i][18:-4], f'.jpg 는 {i}번째이므로 다음에 돌리면 start값을 {i+1}로 주세요')
# pro
# p를 누르면 다음사진 | press 'p' means show next sccne
# b를 누르면 이전사진 | press 'b' means show before scene
# r을 누르면 이상한 사진목록 세이브 | press 'r' means record strange scene name
# q를 누르면 종료 | press 'q' means quit system
start=0
strange_list=[]
i=start
while i<len(jpg_list):
    img_array = np.fromfile(jpg_list[i], np.uint8)
    img = cv2.imdecode(img_array, cv2.IMREAD_COLOR)
    fy, fx, _ = img.shape
    with open('../label_face/'+jpg_list[i][14:-4]+'.txt', 'r') as f:
        code=f.read().split('\n')
    for j in range(len(code)):
        _,x,y,w,h=code[j].split(' ')
        x=float(x); y=float(y); w=float(w); h=float(h)
        x1=round(-fx/2*w+fx*x)
        x2=round(fx/2*w+fx*x)
        y1=round(-fy/2*h+fy*y)
        y2=round(fy/2*h+fy*y)
        cv2.rectangle(img, (x1,y1), (x2,y2), (0,0,255),5)
    cv2.imshow(str(i), img)
    cv2.moveWindow(str(i),-16,-31) # 창 위치 조절
    key=cv2.waitKey()
    if key == ord('q'):
        break
    if key == ord('r'):
        strange_list.append(jpg_list[i][18:-4]+'.jpg')
        i+=1
        cv2.destroyAllWindows()
    if key == ord('p'):
        i+=1
        cv2.destroyAllWindows()
    if key == ord('b'):
        i-=1
        cv2.destroyAllWindows()
    cv2.destroyAllWindows()
cv2.destroyAllWindows()
print(jpg_list[i][18:-4],'.jpg 까지 확인하였습니다.')
print(jpg_list[i][18:-4], f'.jpg 는 {i}번째이므로 다음에 돌리면 start값을 {i+1}로 주세요')
print(x,y,w,h) #4522
s=''
for i in range(len(strange_list)):
    s+=strange_list[i]
    s+='\n'
with open('strange_wildboar.txt', 'a') as f:
    f.write(s)
#880
os.getcwd()
with open('strange_wildboar.txt', 'r') as f:
    file_list=f.read().split('\n')
print(len(file_list))
file_list[-3:]
file_list.pop(-1)
cd ../image_wildboar/
'image_'+file_list[0]
for i in range(len(file_list)):
    os.remove(file_list[i])
len(jpg_list)
# pro reverse
# p를 누르면 다음사진 | press 'p' means show next sccne
# b를 누르면 이전사진 | press 'b' means show before scene
# r을 누르면 이상한 사진목록 세이브 | press 'r' means record strange scene name
# q를 누르면 종료 | press 'q' means quit system
start=10525
strange_list=[]
i=start
while i<len(jpg_list):
    img_array = np.fromfile(jpg_list[i], np.uint8)
    img = cv2.imdecode(img_array, cv2.IMREAD_COLOR)
    fy, fx, _ = img.shape
    with open('../label_gorani/'+jpg_list[i][16:-4]+'.txt', 'r') as f:
        code=f.read().split('\n')
    for j in range(len(code)):
        _,x,y,w,h=code[j].split(' ')
        x=float(x); y=float(y); w=float(w); h=float(h)
        x1=round(-fx/2*w+fx*x)
        x2=round(fx/2*w+fx*x)
        y1=round(-fy/2*h+fy*y)
        y2=round(fy/2*h+fy*y)
        cv2.rectangle(img, (x1,y1), (x2,y2), (0,0,255),5)
    cv2.imshow(str(i), img)
    cv2.moveWindow(str(i),-16,-31) # 창 위치 조절
    key=cv2.waitKey()
    if key == ord('q'):
        break
    if key == ord('r'):
        strange_list.append(jpg_list[i][18:-4]+'.jpg')
        i-=1
        cv2.destroyAllWindows()
    if key == ord('p'):
        i-=1
        cv2.destroyAllWindows()
    if key == ord('b'):
        i+=1
        cv2.destroyAllWindows()
    cv2.destroyAllWindows()
cv2.destroyAllWindows()
print(jpg_list[i][18:-4],'.jpg 까지 확인하였습니다.')
print(jpg_list[i][18:-4], f'.jpg 는 {i}번째이므로 다음에 돌리면 start값을 {i+1}로 주세요')
s=''
for i in range(len(strange_list)):
    s+=strange_list[i]
    s+='\n'
print(s)
s='wild boars like gorakkk'
'wild boar' in s or gorani in s<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2118073537027447, 'fraction_numerical': 0.05323666494044536, 'mean_word_length': 3.8449573507275465, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '102838', 'license': 'MIT', 'n_tokens_mistral': 4910, 'n_tokens_neox': 5073, 'n_words': 768, 'path': 'bbox_image.ipynb', 'repo_name': 'Tripleler/NationalPark_Project', 'size': '9655'}