**Hello I'm working on a web using django and I want to connect with the be cnn . model But after uploading an image to be processed, this error appears What's the problem? **
from django.http import request
from django.shortcuts import render ,redirect
from django.http import HttpResponse
from .forms import Images
from django.contrib.auth.decorators import login_required
import cv2
import numpy as np
from keras.models import load_model
import h5py
def image_upload(request):
data = {}
form=Images(request.POST or None, request.FILES or None)
data["info"]=form
if request.POST:
if form.is_valid():
new_form = form.save(commit=False)
new_form.user = request.user
new_form.save()
label_dict={0:'Covid19 Negative', 1:'Covid19 Positive'}
img_size = 100
path = 'C:/Users/Dr.Esraa/Desktop/project_covid/covid_19%s'% new_form.Image.url
img = cv2.imread(path)
gray = cv2.cvtColor(np.float32(img), cv2.COLOR_RGB2GRAY)
resized = cv2.resize(gray ,(img_size , img_size) )
data_array = np.array(resized)/255
data = resized.reshape(-1,img_size,img_size,1)
model_loded = load_model(r"C:\Users\Dr.Esraa\Desktop\project_covid\covid_19\test_img")
predectied = model_loded.predict(data)
result=np.argmax(predectied,axis=1)[0]
accuracy=float(np.max(predectied,axis=1)[0])
label=label_dict[result]
data = {'label':label, 'result':result, 'accuracy':accuracy, 'url':
new_form.Image.url, 'info': form}
return render(request, 'test_img/test.html', data)
return render(request, 'test_img/image_upload.html',data)
error at /image_upload/
OpenCV(4.5.2) :-1: error: (-5:Bad argument) in function 'cvtColor'
Overload resolution failed:
- src is not a numpy array, neither a scalar
- Expected Ptr<cv::UMat> for argument 'src' Request Method: POST Request URL: http://127.0.0.1:8000/image_upload/ Django Version: 3.2.4 Exception Type: error Exception Value:
OpenCV(4.5.2) :-1: error: (-5:Bad argument) in function 'cvtColor' Overload resolution failed:- src is not a numpy array, neither a scalar
- Expected Ptr<cv::UMat> for argument 'src' Exception Location: C:\Users\User\Desktop\project_covid\covid_19\test_img\views.py, line 34, in image_upload Python Executable: C:\Users\User\Desktop\project_covid\Scripts\python.exe Python Version: 3.9.2 Python Path:
['C:\Users\User\Desktop\project_covid\covid_19', 'C:\Users\User\AppData\Local\Programs\Python\Python39\python39.zip', 'C:\Users\User\AppData\Local\Programs\Python\Python39\DLLs', 'C:\Users\User\AppData\Local\Programs\Python\Python39\lib', 'C:\Users\User\AppData\Local\Programs\Python\Python39', 'C:\Users\User\Desktop\project_covid', 'C:\Users\User\Desktop\project_covid\lib\site-packages', 'C:\Users\User\Desktop\project_covid\lib\site-packages\win32', 'C:\Users\User\Desktop\project_covid\lib\site-packages\win32\lib', 'C:\Users\User\Desktop\project_covid\lib\site-packages\Pythonwin'] Server time: Thu, 15 Jul 2021 15:52:13 +0000 Traceback Switch to copy-and-paste view C:\Users\User\Desktop\project_covid\lib\site-packages\django\core\handlers\exception.py, line 47, in inner response = get_response(request) … ▶ Local vars C:\Users\User\Desktop\project_covid\lib\site-packages\django\core\handlers\base.py, line 181, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) … ▶ Local vars C:\Users\User\Desktop\project_covid\lib\site-packages\django\contrib\auth\decorators.py, line 21, in _wrapped_view return view_func(request, *args, **kwargs) … ▶ Local vars C:\Users\User\Desktop\project_covid\covid_19\test_img\views.py, line 34, in image_upload gray = cv2.cvtColor(np.float32(img), cv2.COLOR_RGB2GRAY) … ▶ Local vars