2014-11-20 14 views
5

creo un'immagine rossa e cercare di salvarlo tramite cv2.imwriteTypeError: tipo di dati img = 17 non è supportato

import numpy as np 
    import cv2 

    RED = [0, 0, 255] 
    IMAGE_SIZE = 100 

    image = np.empty([IMAGE_SIZE, IMAGE_SIZE], dtype=type(RED)) 
    for i in range(IMAGE_SIZE): 
     for j in range(IMAGE_SIZE): 
      image[i, j] = RED 

    cv2.imwrite("red.png", image) 

Ma ottengo l'errore

 File "C:/Users/Andrew/Desktop/Programms/image-processing-cource/Tracks.py", line 11, in save_image 
cv2.imwrite(name, image) 
    TypeError: img data type = 17 is not supported 

Come risolvere il problema?

Grazie!

+0

Perché si utilizza 'DTYPE = tipo di (RED)' 'per image'? 'type (RED)' è una lista python; usando ciò rende 'image' una matrice di oggetti python (e non una con un tipo numerico). Perché non usare, ad esempio, 'dtype = int'? –

+0

Se uso 'dtype = type (int)' (e 'RED = 200') allora otterrò lo stesso errore – IvanovAndrew

+0

Ue' dtype = int' (non 'type (int)'). Impostando 'dtype' si imposta il tipo di dati degli elementi dell'array che si sta creando. –

risposta

2

dtype = type(RED) fornisce il tipo list e non il tipo int.

è necessario:

image = np.empty([IMAGE_SIZE, IMAGE_SIZE, 3], dtype=type(RED[0])) 
Problemi correlati