我正在尝试将文件从 java 传递给 python。要加载我使用毕加索的文件,因为我要获取宽度和高度。但是当我调用同一个文件将它传递给 python 时,它给了我一个错误。这是java代码:
Picasso.get().load(R.drawable.f21).into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
imageString = getStringImage(bitmap);
iv.setImageBitmap(bitmap);
PyObject pyo = py.getModule("Heat");
PyObject obj = pyo.callAttr("Python", bitmap, lrange, urange);
String str = obj.toString();
byte data[] = android.util.Base64.decode(str, Base64.DEFAULT);
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
iv2.setImageBitmap(bmp);
我得到的错误是:
com.chaquo.python.PyException: TypeError: Expected Ptr<cv::UMat> for argument '%s'
at <python>Heat.Python(Heat.py:9)
at com.chaquo.python.PyObject.callAttr(PyObject.java:209)
但是当我尝试从drawable加载图像时,它没有成功传递给python脚本。它没有向我显示任何错误,但显示以下消息:
I/Choreographer: Skipped 129 frames! The application may be doing too much work on its main thread.
如何将图像从 java 传递到 python 脚本。
我的python代码是:
import numpy as np
import cv2
import os
import matplotlib.pyplot as plt
from PIL import Image
def Python(croppedImage,lowerRange, upperRange):
mask_yellow = cv2.inRange(croppedImage,lowerRange,upperRange)
dilatation_type = cv2.MORPH_RECT
hMin = 1
sMin = 0
vMin = 0
hMax = 107
sMax = 38
vMax = 265
output = image
wait_time = 30
lower = np.array([hMin, sMin, vMin])
upper = np.array([hMax, sMax, vMax])
print(lower,upper)
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, lower, upper)
-----------------------------This is just a part of code---------------------------------