Can I upload a downloaded image directly to cv2?

I have a downloaded file in memory. I want to manipulate a cv2 file. I am currently writing a file to disk and then reading it from cv2. How can I skip file recording and upload it directly using cv2?

file = request.files['file'] # if file and allowed_file(file.filename): # save file filename = secure_filename(file.filename) file_path = os.path.join(dressrank.config['SHOW_IMG_FOLDER'], filename); file.save(file_path) img_path = file_path # COLOR FATURE EXTRACTION img = read_img(img_path) img =img_resize(img, 500) 
+5
source share
1 answer

Create a numpy array using the loaded data. Decode this array using cv2.

 img = cv2.imdecode(numpy.fromstring(request.files['file'].read(), numpy.uint8), cv2.CV_LOAD_IMAGE_UNCHANGED) 

See also: Loading Python OpenCV Image from Byte String

+8
source

Source: https://habr.com/ru/post/1209293/


All Articles