HyeonJun@khj MINGW64 ~/Desktop/2018-1-capstone_design_1-Automated_calculation_system (master)
$ git add * HyeonJun@khj MINGW64 ~/Desktop/2018-1-capstone_design_1-Automated_calculation_system (master) $ git commit -m
Showing
2 changed files
with
46 additions
and
1 deletions
... | @@ -39,4 +39,9 @@ python test 폴더에는 test에 필요하지 않은 train 부분을 삭제함 | ... | @@ -39,4 +39,9 @@ python test 폴더에는 test에 필요하지 않은 train 부분을 삭제함 |
39 | 5) params.txt : 속도향상을 위해 params.pkl파일을 params.txt로 변환 | 39 | 5) params.txt : 속도향상을 위해 params.pkl파일을 params.txt로 변환 |
40 | 6) main.cpp | 40 | 6) main.cpp |
41 | *c++ 컴파일러 버전 11이상 | 41 | *c++ 컴파일러 버전 11이상 |
42 | - *프로젝트 생성 시 sdl 검사 체크 해제 | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
42 | + *프로젝트 생성 시 sdl 검사 체크 해제 | ||
43 | + | ||
44 | + | ||
45 | +10. google_image_crwaling 코드 추가 | ||
46 | + | ||
47 | +필요한 데이터셋을 만들기 위한 google_image_crwaling 코드 추가 | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | +import requests | ||
2 | +from lxml.html import parse | ||
3 | +from io import StringIO | ||
4 | +import os, sys | ||
5 | +from PIL import Image | ||
6 | +import urllib.request | ||
7 | + | ||
8 | + | ||
9 | +# 검색할 이미지의 키워드 입력 | ||
10 | +keyword = input("검색할 이미지를 입력하세요 : ") | ||
11 | +url = 'https://www.google.co.kr/search?q='+keyword+'&source=lnms&tbm=isch&sa=X&ved=0ahUKEwic-taB9IXVAhWDHpQKHXOjC14Q_AUIBigB&biw=1842&bih=990' | ||
12 | + | ||
13 | + # html 소스 가져오기 | ||
14 | +text = requests.get(url).text | ||
15 | + | ||
16 | +# html 문서로 파싱 | ||
17 | +text_source = StringIO(text) | ||
18 | +parsed = parse(text_source) | ||
19 | + | ||
20 | +# root node | ||
21 | +doc = parsed.getroot() | ||
22 | + | ||
23 | +# img 경로는 img 태그안에 src에 있음(20개 크롤링) | ||
24 | +imgs = doc.findall('.//img') | ||
25 | + | ||
26 | +img_list = [] # 이미지 경로가 담길 list | ||
27 | +cnt=0 | ||
28 | + | ||
29 | +for a in imgs: | ||
30 | + if cnt>0 and cnt<11: | ||
31 | + img_list.append(a.get('src')) | ||
32 | + image_url = a.get('src') | ||
33 | + filename = keyword + str(cnt) + '.jpg' | ||
34 | + fd = os.open(filename, os.O_WRONLY|os.O_BINARY|os.O_CREAT) | ||
35 | + ud = urllib.request.urlopen(image_url) | ||
36 | + binary = ud.read() | ||
37 | + os.write(fd, binary) | ||
38 | + os.close(fd) | ||
39 | + print(filename + ' download complete') | ||
40 | + cnt = cnt+1 |
-
Please register or login to post a comment