Drawing in OpenCV and Python

2

I'm doing an application in Python, which using the OpenCV library and passing it the height and width, I create a RGB image with the past dimensions and in which I can draw and gurantee later.

I'm trying something like this:

import numpy as np
import cv2

def imRGB(X, Y):
    img = np.zeros((X, Y, 3), np.uint8)
    cv2.line(img,(10, 0), (250, 128), (0, 255, 0), 3)
    cv2.circle(img,(447,63), 63, (0,0,255), -1)
    N = img
    N.save("imRGB.jpg")

But I can not get it to work since it throws me errors like:

  

AttributeError: 'numpy.ndarray' object has no attribute 'save'

Could someone help me?

A health and thank you.

    
asked by Alfred 21.02.2018 в 17:56
source

1 answer

2

The method save does not exist for the class ndarray , NumPy does not have this feature, although it is used to work with images as a container taking advantage of its high level mathematical functions to deal with matrices and vectors. In your case you can simply use the method cv2.imwrite to create your image from the NumPy array:

import numpy as np
import cv2

def imRGB(X, Y):
    img = np.zeros((X, Y, 3), np.uint8)
    cv2.line(img,(10, 0), (250, 128), (0, 255, 0), 3)
    cv2.circle(img,(447,63), 63, (0,0,255), -1)
    cv2.imwrite('imRGB.jpg', img)
    
answered by 21.02.2018 / 18:07
source