텍스트 파일이 있습니다. 그것의 용기는 다음과 같이/그것의 모든 다음과 같다 내가 파이썬 2 세트에 이러한 값을 넣어 어떻게, 어쨌든파이썬 - 텍스트 파일에서 세트 만들기
(0, 16, 0)
(0, 17, 0)
(0, 18, 0)
(0, 19, 0)
(0, 20, 0)
(0, 21, 0)
(0, 22, 0)
(0, 22, 1)
(0, 22, 2)
(0, 23, 0)
(0, 23, 4)
(0, 24, 0)
(0, 25, 0)
(0, 25, 1)
(0, 26, 0)
(0, 26, 3)
(0, 26, 4)
(0, 26, 5)
(0, 26, 9)
(0, 27, 0)
(0, 27, 1)
(편집되었습니다. 이것은 처음처럼 보였다하지 무엇도했다) ?
내 가장 최근의 시도는om_set = set(open('Rye Grass.txt').read()
편집 :이 내가 내 텍스트 파일을 가져 오는 데 사용하는 코드입니다. modification.You이 시도 할 수 NP 수입 시간으로 수입 CV2 수입 NumPy와는
om=cv2.imread('spectrum1.png')
om=om.reshape(1,-1,3)
om_list=om.tolist()
om_tuple={tuple(item) for item in om_list[0]}
om_set=set(om_tuple)
im=cv2.imread('1.jpg')
im=cv2.resize(im,(100,100))
im= im.reshape(1,-1,3)
im_list=im.tolist()
im_tuple={tuple(item) for item in im_list[0]}
ColourCount= om_set & set(im_tuple)
with open('Weedlist', 'a') as outputfile:
output = ', '.join([str(tup) for tup in sorted(ColourCount)])
outputfile.write(output)
print 'done'
im=cv2.imread('2.jpg')
im=cv2.resize(im,(100,100))
im= im.reshape(1,-1,3)
im_list=im.tolist()
im_tuple={tuple(item) for item in im_list[0]}
ColourCount= om_set & set(im_tuple)
with open('Weedlist', 'a') as outputfile:
output = ', '.join([str(tup) for tup in sorted(ColourCount)])
outputfile.write(output)
print 'done'
가장 최근의 시도는 om_set = set (open ('Rye Grass.txt'))입니다.) –
파일 내용을 파싱해야합니다.'file.read()'는 모든 것을 긴 문자열로 읽어 들이고,'set()'을 호출하면 모든 문자 집합을 가져옵니다. 그것을 파싱하기 위해서는 정확한 구조가 알려 져야한다. (단지 "헛된 것"이 아니다.) 항상 쉼표로 구분 된 정수의 세 쌍임? –
쉼표로 구분 된 정수의 세 쌍은 항상 픽셀 값이다. –