Hi everyone I use python 3 with opencv library it work's well but I noticed render is displayed in a new window with
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
I just want to allow to user to change brightness on a browser but I got latency
So I decided to create
- python API using flask
- frontend using express server that render an index.html page
I don't know if It's the good way to make image processing with good performances.
Here is my api which work's well
@cross_origin()
@app.route('/brigtness', methods=['GET'])
def brigtness():
image = cv.imread(cv.samples.findFile(MEDIA_PATH + "50cent.jpg"))
if image is None:
print('Could not open or find the image')
exit('error')
new_image = np.zeros(image.shape, image.dtype)
alpha = 1.0 # Simple contrast control
beta = int(request.args.get('id')) # Simple brightness control
# Do the operation new_image(i,j) = alpha*image(i,j) + beta
# Instead of these 'for' loops we could have used simply:
new_image = cv.convertScaleAbs(image, alpha=alpha, beta=beta)
cv.imwrite(MEDIA_PATH + "50cent-custom.jpg", new_image)
_, data = cv.imencode('.jpeg', new_image)
jpeg_base64 = base64.b64encode(data.tostring())
return jpeg_base64
Here is my script to update brightness to frontend
const axios = require('axios').default;
var $ = require( "jquery" );
require("bootstrap-slider");
$(document).ready(function() {
$("#ex6").slider();
//$("#ex6").on("slideStop", function(slideEvt) {
$("#ex6").on("slide", function(slideEvt) {
$("#ex6SliderVal").text(slideEvt.value);
//createImage(slideEvt.value.toString());
updateBrightness(slideEvt.value.toString());
});
})
function updateBrightness(value) {
axios.get('http://localhost:5000/brigtness?id=' + value)
.then(function (response) {
var base64 = response.data;
refreshImage(base64);
})
.catch(function (error) {
console.log(error);
})
}
function refreshImage(base64) {
$(".img").attr("src", "data:image/jpeg;base64," + base64)
}
My scripts work's well but when I decided to update brightness when slider is triggered by "slide" event I got latency. How can I update brightness with less latency ? How to use python and opencv on a browser ?