我有一个 python 文件,其中包含许多“def”值。当我尝试将 python 文件与 android studio 集成时,出现类型错误。输入是一个图像文件,我希望 lowerRange 和 upperRange 基于该图像,所以我不能为它们定义一个值,因为图像大小每次都会变化。
import numpy as np
import cv2
import os
import matplotlib.pyplot as plt
from PIL import Image
def host(croppedImage,lowerRange, upperRange):
mask_yellow = cv2.inRange(croppedImage,lowerRange,upperRange)
dilatation_type = cv2.MORPH_RECT
dilatation_size = 1
element = cv2.getStructuringElement(dilatation_type, (dilatation_size + 2, dilatation_size+2), (dilatation_size, dilatation_size))
dilated_mask_image = cv2.dilate(mask_yellow, element)
return dilated_mask_image
def DrawContourRect(contour):
rect = cv2.minAreaRect(contour)
return cv2.boxPoints(rect)
-----------------------------This is just a part of code---------------------------------
这是python对象的xml代码:
PyObject pyo = py.getModule("file");
PyObject obj = pyo.callAttr("host", imageString);
错误是这样的:
com.chaquo.python.PyException: TypeError: detect() missing 2 required positional arguments: 'lowerRange' and 'upperRange'
at <python>.chaquopy_java.call(chaquopy_java.pyx:285)
at <python>.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrows(chaquopy_java.pyx:257)
有什么方法可以解决这个问题,chaquopy 如何读取每个“def”值(主机和 DrawContourRect.