Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: img data type = 17 is not supported

I create red image and try to save it via cv2.imwrite

    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)

But I get error

     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

How to fix it?

Thanks!

like image 838
IvanovAndrew Avatar asked Nov 20 '14 22:11

IvanovAndrew


1 Answers

dtype = type(RED) gives you type list and not type int.

you need:

image = np.empty([IMAGE_SIZE, IMAGE_SIZE, 3], dtype=type(RED[0]))
like image 158
laura112 Avatar answered Nov 08 '22 08:11

laura112