편집 기록

편집 기록
  • 프로필 nowp님의 편집
    날짜2022.05.05

    Python cv2 이미지를 y방향으로 일정 간격으로 나누어보려는데 IndexError: list assignment index out of range


    안녕하세요. cv2 연습 중입니다만 for문 부터 뭔가 자꾸 안 되어서 문의 드립니다. 제가 하려는 건 임의의 크기의 이미지를 read하여 x방향 크기는 그대로 하고 y방향으로 일정 간격으로 general하게 나눠보려고 하고 있습니다.

    //Python 3.7.6 // ipynb 사용중
    import cv2
    img_file = 'img.png'
    img_read = cv2.imread(img_file, cv2.IMREAD_GRAYSCALE)
    
    x = 700
    y = 700
    z = y//254
    
    img_rsz = cv2.resize(img_read, (x, y), interpolation=cv2.INTER_LINEAR)
    
    img_cp1 = img_rsz.copy()
    img_cut = []
    
    
    for i in range(z) : 
        img_cut[i] = img_rsz[i*254:i*254+254, 0:x]
    
    
    for i in range(z) :
        cv2.imshow('cut', img_cut[i])    
        cv2.waitKey()
        cv2.destroyAllWindows()
    
    
    
    IndexError                                Traceback (most recent call last)
    <ipython-input-23-923adf7ee222> in <module>
         10 
         11 for i in range(z) :
    ---> 12     img_cut[i] = img_rsz[i*254:i*254+254, 0:x]
         13 
    
    
    IndexError: list assignment index out of range
    
  • 프로필 물먹는하마님의 편집
    날짜2022.05.05

    Python 3.7.6 cv2 간단 문의 드려용


    안녕하세요. cv2 연습 중입니다만 for문 부터 뭔가 자꾸 안 되어서 문의 드립니다. ㅠㅠ 제가 하려는 건 임의의 크기의 이미지를 read하여 x방향 크기는 그대로 하고 y방향으로 일정 간격으로 general하게 나눠보려고 하고 있습니다 ㅠㅠ

    //Python 3.7.6 // ipynb 사용중
    import cv2
    img_file = 'img.png'
    img_read = cv2.imread(img_file, cv2.IMREAD_GRAYSCALE)
    
    x = 700
    y = 700
    z = y//254
    
    img_rsz = cv2.resize(img_read, (x, y), interpolation=cv2.INTER_LINEAR)
    
    img_cp1 = img_rsz.copy()
    img_cut = []
    
    
    for i in range(z) : 
        img_cut[i] = img_rsz[i*254:i*254+254, 0:x]
    
    
    for i in range(z) :
        cv2.imshow('cut', img_cut[i])    
        cv2.waitKey()
        cv2.destroyAllWindows()
    
    
    
    IndexError                                Traceback (most recent call last)
    <ipython-input-23-923adf7ee222> in <module>
         10 
         11 for i in range(z) :
    ---> 12     img_cut[i] = img_rsz[i*254:i*254+254, 0:x]
         13 
    
    
    IndexError: list assignment index out of range