'2022/04/12'에 해당되는 글 2건

  1. 2022.04.12 python openCV / PIL 포맷 변경
  2. 2022.04.12 파이썬 딕셔너리 변수 생성과 리턴 enumerate, zip

필요한 건 openCV로 받아 PIL로 변환하는거라 아래것만 테스트 해봄

import cv2
from PIL

opencv_image=cv2.imread(".\\learning_python.png")
color_coverted = cv2.cvtColor(opencv_image, cv2.COLOR_BGR2RGB)
pil_image=PIL.Image.fromarray(color_coverted)

[링크 : https://www.zinnunkebi.com/python-opencv-pil-convert/]

'Programming > python(파이썬)' 카테고리의 다른 글

pyplot  (0) 2023.10.04
python matplotlib 설치  (0) 2023.03.08
파이썬 딕셔너리 변수 생성과 리턴 enumerate, zip  (0) 2022.04.12
python interactive mode  (0) 2022.03.15
python3 opencv2 checker board  (0) 2022.03.14
Posted by 구차니

발견하게 된 생소한 문법은 아래와 같은데..

enumerate() 함수를 이용해 이름 목록을 열거하고 인덱스와 함께 

name(키) 와 outputs 라는 구조를 쌍으로 묶어 딕셔너리로 돌려준다.

return {name: outputs[i] for i, name in enumerate(self.output_names)}

 

def create_dict():
    ''' Function to return dict '''
    return {i:str(i) for i in range(10)}
numbers = create_dict()
print(numbers)
# {0: '0', 1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8', 9: '9'}

[링크 : https://blog.finxter.com/python-return-dictionary-from-function/]

 

enumerate() 는 내용과 인덱스를 같이 돌려주고 start 키워드를 이용해 시작 인덱스를 0이 아닌 것으로 설정이 가능하다.

>>> for entry in enumerate(['A', 'B', 'C']):
...     print(entry)
...
(0, 'A')
(1, 'B')
(2, 'C')

[링크 : https://www.daleseo.com/python-enumerate/]

 

enumerate()와 유사하게 두개의 배열을 하나의 쌍으로 묶어주는 함수

>>> numbers = [1, 2, 3]
>>> letters = ["A", "B", "C"]
>>> for pair in zip(numbers, letters):
...     print(pair)
...
(1, 'A')
(2, 'B')
(3, 'C')

[링크 : https://www.daleseo.com/python-zip/]

'Programming > python(파이썬)' 카테고리의 다른 글

python matplotlib 설치  (0) 2023.03.08
python openCV / PIL 포맷 변경  (0) 2022.04.12
python interactive mode  (0) 2022.03.15
python3 opencv2 checker board  (0) 2022.03.14
pdb  (0) 2022.03.14
Posted by 구차니