I am currently developing a simple website and I am having trouble as I am new to Django and AJAX.
I would like for the user to select an image from their computer and then be able to process and display the image without refreshing the page. I was able to do simple color thresholding using only JavaScript, however some of the more complex processing will need to be done using Python, which is why I am using Django.
Javascript
$("#interactBtn").click(function() {
var img = document.getElementById('inputImageFileInput').files[0];
$.ajax({
type: "POST",
url: 'threshold', //does this look okay?
data: img,
}).done(function(data) {
var canvas = document.getElementById('imagesTabProccessedImg');
var context = canvas.getContext('2d');
context.clearRect(0, 0, canvas.width, canvas.height);
context.putImageData(data, 0, 0);
}
});
views.py
def threshold(img):
# how to load image as OpenCV image
# imagine proccessing here
return img
I'm not quite sure where to go from here. From what I have researched, I think it should be possible, I'm just lost.
- Will my ajax request send the image data?
- In what format will the image be sent to the python code?
Thanks in advance for the help!