N
N
NonameFromUkraine2021-08-12 18:41:36
Python
NonameFromUkraine, 2021-08-12 18:41:36

How to process an image through CV2?

I take a screenshot of the screen and convert its image to a different color space. I need to create a new image without saving it to disk, and then work with it.
How to do?
I tried like this:

image = pyautogui.screenshot(region=(514, 495, 264, 12))
    image = cv2.cvtColor(np.array(image), cv2.COLOR_BGR2GRAY)
    im=Image.fromarray(image, 'RGB') # Выдает ошибку ValueError: not enough image data
    #cv2.imwrite("pic.png", image) так я делал раньше, но мне надо без создания файла
    #im = Image.open('pic.png')
  
    for i in range(1, 11):
        if i == 10:
            im_crop = im.crop((244, 1, 264, 12))
        else:
            im_crop = im.crop((jump * (i - 1)+2, 1, 27 * (i - 1) + 16, 12))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-08-12
@NonameFromUkraine

It's not clear what exactly you are trying to do. If you just translate the screenshot into a different color space ,
then these two lines enough. Further, it is better to do crop using cv2, since numpy arrays are enough for this (namely, this is how cv2 stores images).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question