我在应用程序中显示边界框时遇到问题。
我的应用程序可以检测图像中的文本并显示在滚动视图中检测到的文本。
但我想将显示方式从在滚动视图中显示字符更改为按包围该图像中文本的边界框,然后显示结果。
这是我的代码,结果显示在滚动视图中。
BitmapDrawable drawable = (BitmapDrawable) mImageView.getDrawable();
Bitmap bitmap = drawable.getBitmap();
lvLabel.setBackground(drawable);
String data = CloudVision.convertBitmapToBase64String(bitmap);
while (data.getBytes().length > 10400000){
bitmap = Bitmap.createScaledBitmap(bitmap,(int)(bitmap.getWidth()*0.8), (int)(bitmap.getHeight()*0.8), true);
data = CloudVision.convertBitmapToBase64String(bitmap);;
}
CVRequest request = createCVRequest(data);
CloudVision.runImageDetection(apiKey, request, this);
}
private CVRequest createCVRequest(String data) {
CVRequest.Image image = new CVRequest.Image(data);
CVRequest.Feature feature = new CVRequest.Feature(CVRequest.FeatureType.TEXT_DETECTION, 6);
List<String> imgHint = new ArrayList<>();
imgHint.add("en");
imgHint.add("th");
CVRequest.ImageContext imageContext = new CVRequest.ImageContext(imgHint,null);
List<CVRequest.Feature> featureList = new ArrayList<>();
featureList.add(feature);
List<CVRequest.Request> requestList = new ArrayList<>();
requestList.add(new CVRequest.Request(image, featureList));
return new CVRequest(requestList);
}
private void setCVResponse(CVResponse cvResponse) {
if (cvResponse != null && cvResponse.isResponsesAvailable()) {
CVResponse.Response response = cvResponse.getResponse(0);
if (response.isTextAvailable()) {
LabelAdapter adapter = new LabelAdapter(response.getTexts());
lvLabel.setAdapter(adapter);
}
}
hideLoading();
}```