I am working on a project related to image processing. Currently, I am taking a image from the webcam and saving it in some folder. Then I display that image as a background image on the div. This works fine. But when I take the image again, the background image still remains the same. But when I see the image in the folder, it has changed.
Note: Both the images are saved by same name. So, previous image is just replaced by current image. And the image is taken by clicking a button.
html code:
<button id = "click" onclick = "mooddetect()">MOODY</button>
function mooddetect() {
$.ajax({
url: '/mooddetect/',
type:"POST",
cache:false,
success: function(input) {
var x = document.getElementById('photo');
x.style.backgroundImage = "url('/static/detect/test.jpg')";
},
failure: function(data) {
alert('Got an error dude');
}
});
}
views.py:
def get_image(camera):
retval, im = camera.read()
return im
def webcam():
camera_port = 0
ramp_frames = 30
camera = cv2.VideoCapture(camera_port)
for i in xrange(ramp_frames):
temp = get_image(camera)
print("Taking image...")
camera_capture = get_image(camera)
file = "./music/static/detect/test.jpg"
cv2.imwrite(file, camera_capture)
del(camera)
@csrf_exempt
def mooddetect(request):
webcam()
return HttpResponse("success")