【问题标题】:Why cv2.imread returns none when using django python?为什么使用 django python 时 cv2.imread 没有返回?
【发布时间】:2021-03-19 08:21:08
【问题描述】:

我在 django 中使用 opencv-python,但是当我使用 cv2.imread 时,它只返回 nonetype。我该如何解决这个问题?

from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework import status
from . import serializers
from .serializers import call_serializers
from .apps import BmiEstimationConfig
import pickle
from skimage import io

class BMIEstimationView(APIView):
    serializer_class = serializers.call_serializers

    def post(self, request):
        serializer = serializers.call_serializers(data=request.data)
        serializer.is_valid(raise_exception=True)
        file = request.FILES['file']

        import cv2
        image = cv2.imread(file)
        print(image)```

got this :
> TypeError: bad argument type for built-in operation

【问题讨论】:

  • 向我们展示此错误中涉及的代码。显示你传递给cv2.imread的内容。
  • 需要更多细节

标签: python django opencv cv2 opencv-python


【解决方案1】:

请确认 cv2.imread() 的语法

Syntax: cv2.imread(path, flag)

Parameters:
path: A string representing the path of the image to be read.
flag: It specifies the way in which image should be read. It’s default value is cv2.IMREAD_COLOR

Return Value: This method returns an image that is loaded from the specified file.

还请提供图片的完整路径

查看示例click here

示例图片:

【讨论】:

  • 我认为如果我们不指定标志,标志将自动设置为默认值(1)对吧?为了确保这一点,我尝试添加标志,但仍然无法正常工作@sourab maity
  • 请看上图,是的,它是自动设置的
  • 如果我们从 django 上传图片怎么办?它不是路径,对吧?如何解决?有必要先保存吗?或者我们可以在不先保存的情况下进行处理? @sourab maity
猜你喜欢
  • 2020-09-19
  • 2019-01-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-30
  • 1970-01-01
  • 2019-12-26
相关资源
最近更新 更多