How to get image objects from Picture File Stream by cv2

I need to do some image processing recently. When I get the picture stream after a series of protocol parsing and decoding, the next step is to use cv2 to process the picture. First, I need to get the picture object of cv2.
generally
import cv2
img = cv2.imread ("test.jpg")
so you can get the img object directly.
but I want to convert directly in memory. I don"t want to write to the file and read it in cv2, so I can skip the step of image caching.
with the help of the great gods, I have been tinkering with it for a long time. How can it be realized?
such as
fc= open ("test.jpg", "rb"). Read ()
) when fc is the file stream of the image, which is the same as the file stream I processed.
so how do I read it in cv2 now?
cv2.imread (fc) is definitely wrong.

Mar.16,2022

the first floor is very serious, and there is nothing wrong with the logic, but it is a pity that the answer is not the question.


fc= open("test.jpg","rb").read() 

-sharpfcnumpy
-sharpfcascii
-sharpnpfcascii)
-sharpfc100fileNPArry100
fileNPArray = np.fromstring(fc, np.uint8)


-sharpcv2.IMREAD_COLOR 
-sharpcv2.IMREAD_GRAYSCALE 
img = cv2.imdecode(fileNPArray ,cv2.IMREAD_COLOR)

-sharpimg cv2.imread() 

python3 cv2

>>> import cv -sharp cv2
>>> url='https://img.codeshelper.com/upload/img/2022/03/16/hl222fknxhx4070.jpg'
>>> def get_net_img(url):
    img = None
    cap=cv.VideoCapture(url)
    if cap.isOpened():
        ret,img=cap.read()
    return img

>>> img = get_net_img(url)
>>> cv.imshow('photo', img)
>>> 

method 2

-sharp 2
import cv
import requests as req
import numpy as np

url2 = r'https://avatar-static.segmentfault.com/253/210/2532103026-593f867b9c17e'
rsp = req.get(url2)
cont = rsp.content
buf = np.asarray(bytearray(cont), dtype="uint8") -sharp numpy
img = cv.imdecode(buf, cv.IMREAD_COLOR) -sharp 
cv.imshow('pic', img) -sharp 
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b32e22-2be42.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b32e22-2be42.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?