March 2019
Intermediate to advanced
532 pages
13h 2m
English
Script hello_opencv.py is coded in order to show how you can use OpenCV to perform a very basic web computer vision application. The code of this script is shown next:
# Import required packages:import cv2from flask import Flask, request, make_responseimport numpy as npimport urllib.requestapp = Flask(__name__)@app.route('/canny', methods=['GET'])def canny_processing(): # Get the image: with urllib.request.urlopen(request.args.get('url')) as url: image_array = np.asarray(bytearray(url.read()), dtype=np.uint8) # Convert the image to OpenCV format: img_opencv = cv2.imdecode(image_array, -1) # Convert image to grayscale: gray = cv2.cvtColor(img_opencv, cv2.COLOR_BGR2GRAY) # Perform canny edge ...