I'm pretty new with React and Python Flask. I'm trying to read a QR Image from React Front-end, and pass it to Python Flask back end to handle decoding the image. I got the blob from React: blob:http://localhost:3000/da6af34a-b103-4212-884b-4aec8719574d. I'm trying to pass this string to python and read it; however, I'm not sure how I can read and image with blob. Any idea what I should do? Any input is appreciated. Thank you.
#api.route('/api/read_qr_code/<srcQrImg>', methods=["GET"])
def read_qr(srcQrImg):
print(srcQrImg)
img = Image.open(srcQrImg)
output = pyzbar.decode(img)
qr_data = str(output[0].data).lstrip("b'").rstrip("'")
qr_data = json.loads(qr_data)
Related
I have used python to upload an image from my desktop to imgur in the jpg format but it converts the image to jpeg format and this is no good for the use I am looking to use this for. I was wondering if anyone knows how to keep it from changing. here is my code with my keys taken out.
from imgurpython import ImgurClient
def uploadimage():
client_id = 'hi'
client_secret = 'hi'
client = ImgurClient(client_id, client_secret)
uploadedImage = client.upload_from_path(r"C:\Users\will_\Documents\PSA Card Project Files\Price Checker\IMG_1632.jpg", config=None, anon=True)
link = "{0}".format(uploadedImage['link'])
print(link)
uploadimage()
Edit: The extension is the thing that changes from .jpg to .jpeg when I go view the uploaded image. This is a problem because the website that I need this link for, requires that the image be jpg or png or another format on their list but jpeg is not one of those formats on that list.
I am making a program in python that scans receipts and relies on an OCR response using the OCRSpace API. It has worked perfectly in that past with a couple hundred tries but when uploading an image to my flask server from an iphone instead of a computer, the image's contents do not have an OCR result. I have tried using the same image on their website and it gives a normal response but with my flask app it returns
parsed_results = result.get("ParsedResults")[0]
TypeError: 'NoneType' object is not subscriptable
I am using the code:
img = cv2.imread(file_path)
height, width, _ = img.shape
roi = img[0: height, 0: width]
_, compressedimage = cv2.imencode(".jpg", roi, [1, 90])
file_bytes = io.BytesIO(compressedimage)
url_api = "https://api.ocr.space/parse/image"
result = requests.post(url_api,
files = {os.path.join(r'PATH', file_name): file_bytes},
data = {"apikey": "KEY",
"language": "eng",
#"OCREngine": 2,
"isTable": True})
result = result.content.decode()
result = json.loads(result)
parsed_results = result.get("ParsedResults")[0]
global OCRText
OCRText = parsed_results.get("ParsedText")
Thanks for any help in advance!
iPhones and iPads as of iOS 11 use HEIF as standard; there are no incompatibilities when transferring to PC or sending e.g. by sharing, as the images are converted to the widely supported JPEG format; however, incompatibilities arise when using cloud services e.g. Google Photos.
High Efficiency Image File Format (HEIF)
As #rob247 posted IPhones are using HEIF format by default(official link here)
So when you uploaded photos to the script please try converting it to JPEG before use since opencv does not support *heif,*avif,*heic yet see issue #14534 also view the list of supported formats at opencv imread if you prefer other formats
I'm trying to save images from the Spotify API
I get album art in the form of a link:
https://i.scdn.co/image/ab67616d00004851c96f7c7b077c224975b4c5ce
I think it's a jpg file.
I run into errors in trying to display or save this in python.
I'm not even sure how I'm meant to format something like:
Do I need str around the link?
str(https://i.scdn.co/image/ab67616d00004851c96f7c7b077c224975b4c5ce)
Or should I create a new variable e.g.
image_path = 'https://i.scdn.co/image/ab67616d00004851c96f7c7b077c224975b4c5ce'
And then:
im1 = im1.save(image_path)
Your second suggestion should work with an addition of actually downloading the image using urllib.request:
import urllib.request
image_path = 'https://i.scdn.co/image/ab67616d00004851c96f7c7b077c224975b4c5ce'
urllib.request.urlretrieve(image_path, "image.jpg")
I'm writing a Rest-API function which should take a video from a post request, process the video using OpenCV and return a text response. I got stuck at reading the video from its string representation.
I looked at documentations that describe how to read a video in OpenCV and all of them are either reading from a path or from the webcam. For example, cv2.VideoCapture or FileVideoStream from imutils are all using the file path to load the video. However, I want to avoid redundant IO operations and don't want to write the video to a file first.
Related part in my project:
#app.route('/processvideo', methods = ['POST'])
def process_video():
# read as string
fStr = request.files['file'].read() # file is read as string from the request
npimg = np.fromstring(fStr, np.uint8) # string data is converted to numpy array.
# image = cv2.imdecode(npimg, cv2.IMREAD_COLOR) # this functions doesn't work, because it only takes image, not video.
return jsonify( { 'output': 'test' } )
I'm sending the request in cli for test as follows:
curl -F 'file=#demo.mp4' http://localhost:5000/processvideo
I want to process the incoming video frame by frame, so I need the frames as an image. Thanks from now for any help.
I am trying to upload an image that has been converted to grayscale, like this:
blob_path = os.path.join(os.path.split(__file__)[0], 'static/img/blob-masks/1.png')
blob = Image.open(blob_path).convert('L')
buffer = StringIO()
blob.save(buffer)
upload_image(buffer.getvalue(),"foo.png")
But it just seem to upload a black square.
If I got to the command line python and run:
col = Image.open("/static/img/blob-masks/5.png")
col.convert('L')
col.save("result_bw.png")
result_bw.png is perfect. What is going wrong?
Is there a reason you can't just upload the greyscale image after you convert it? Like:
image = Image.open('static/img/blob-masks/1.png')
image.convert('L')
image.save("temp/bw.png")
upload_image("temp/bw.png")
# maybe delete the temporary file when you're done
import os
os.remove("temp/bw.png")
I'm not sure how your upload_image() function works, but when I upload using django if I do any manipulations I write a temporary file and then re-import. If I don't manipulate the image at all I can just upload it directly.