OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

io.UnsupportedOperation: fileno

  • Thread starter Thread starter parham mazahery
  • Start date Start date
P

parham mazahery

Guest
in django i want to receive a file from a form and then pass it to a function, then do some OCR with it. but i get the io.UnsupportedOperation: fileno error. here is part of views.py:

Code:
@login_required(login_url='/profile/login/')
def repairman_profile(request):
    user = request.user
    repairman = RepairmanUser.objects.get(user=user)

    if request.method == 'POST':
        plate_form = PlateForm(request.POST, request.FILES)

        if plate_form.is_valid():
            plate = recognize_plate(request.FILES["plate_image"])
            return HttpResponse(plate)
    else:
        plate_form = PlateForm()


    context = {
        "repairman": repairman,
        'plate_form': plate_form,
    }
    return render(request, 'repairman/profile.html', context=context)

here is the recognize_plate() function:

Code:
def recognize_plate(plate):
    results = {}
    # load models
    model = Model.load("hezarai/crnn-fa-64x256-license-plate-recognition")
    license_plate_detector = YOLO('repairman/plate_recognition/best.pt')

    # load image
    # cap = cv2.imread(plate)


    frame = cv2.imread(plate)

the line frame = cv2.imread(plate) is where the error happens.

here is django log:

Code:
Internal Server Error: /profile/
Traceback (most recent call last):
  File "D:\Tamirauto\WebApp\venv\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "D:\Tamirauto\WebApp\venv\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Tamirauto\WebApp\venv\Lib\site-packages\django\contrib\auth\decorators.py", line 23, in _wrapper_view
    return view_func(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Tamirauto\WebApp\tamirauto\repairman\views.py", line 94, in repairman_profile
    plate = recognize_plate(request.FILES["plate_image"])
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Tamirauto\WebApp\tamirauto\repairman\plate_recognition\main.py", line 18, in recognize_plate
    frame = cv2.imread(plate)
            ^^^^^^^^^^^^^^^^^
  File "D:\Tamirauto\WebApp\venv\Lib\site-packages\ultralytics\utils\patches.py", line 26, in imread
    return cv2.imdecode(np.fromfile(filename, np.uint8), flags)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
io.UnsupportedOperation: fileno
<p>in django i want to receive a file from a form and then pass it to a function, then do some OCR with it. but i get the <code>io.UnsupportedOperation: fileno</code> error.
here is part of views.py:</p>
<pre><code>@login_required(login_url='/profile/login/')
def repairman_profile(request):
user = request.user
repairman = RepairmanUser.objects.get(user=user)

if request.method == 'POST':
plate_form = PlateForm(request.POST, request.FILES)

if plate_form.is_valid():
plate = recognize_plate(request.FILES["plate_image"])
return HttpResponse(plate)
else:
plate_form = PlateForm()


context = {
"repairman": repairman,
'plate_form': plate_form,
}
return render(request, 'repairman/profile.html', context=context)
</code></pre>
<p>here is the recognize_plate() function:</p>
<pre><code>def recognize_plate(plate):
results = {}
# load models
model = Model.load("hezarai/crnn-fa-64x256-license-plate-recognition")
license_plate_detector = YOLO('repairman/plate_recognition/best.pt')

# load image
# cap = cv2.imread(plate)


frame = cv2.imread(plate)
</code></pre>
<p>the line <code>frame = cv2.imread(plate)</code> is where the error happens.</p>
<p>here is django log:</p>
<pre><code>Internal Server Error: /profile/
Traceback (most recent call last):
File "D:\Tamirauto\WebApp\venv\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "D:\Tamirauto\WebApp\venv\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Tamirauto\WebApp\venv\Lib\site-packages\django\contrib\auth\decorators.py", line 23, in _wrapper_view
return view_func(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Tamirauto\WebApp\tamirauto\repairman\views.py", line 94, in repairman_profile
plate = recognize_plate(request.FILES["plate_image"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Tamirauto\WebApp\tamirauto\repairman\plate_recognition\main.py", line 18, in recognize_plate
frame = cv2.imread(plate)
^^^^^^^^^^^^^^^^^
File "D:\Tamirauto\WebApp\venv\Lib\site-packages\ultralytics\utils\patches.py", line 26, in imread
return cv2.imdecode(np.fromfile(filename, np.uint8), flags)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
io.UnsupportedOperation: fileno
</code></pre>
 

Latest posts

I
Replies
0
Views
1
impact christian
I
Top