- Use the VisionBase class to connect to HiAI Engine. ConnectManager is a connection management class that processes connection establishment, disconnection, and connection waiting. For details, see the demo code.
VisionBase.init(getApplicationContext(),
ConnectManager.getInstance().getmConnectionCallback());
- Input the image to be processed.
VisionImage image = VisionImage.fromBitmap(mBitmap);
- Construct the super-resolution processing class.
ImageSuperResolution superResolution = new ImageSuperResolution(mContext);
- Construct and set super-resolution parameters. MODE_OUT specifies that the inter-process communication mode is used, while MODE_IN specifies the intra-process mode. scale specifies the upscaling factor, and SISR_QUALITY_HIGH specifies the quality. Finally, set the configured parameters in the super-resolution object.
SISRConfiguration paras = new SISRConfiguration
.Builder()
.setProcessMode(VisionConfiguration.MODE_OUT)
.build();
paras.setScale(scale);
paras.setQuality(SISRConfiguration.SISR_QUALITY_HIGH);
superResolution.setSuperResolutionConfiguration(paras);
- Perform super-resolution and process the result. The doSuperResolution function contains three parameters. The first parameter indicates the input image. If the third parameter is not empty, doSuperResolution is called in asynchronous mode, and the result is returned through callback. If the third parameter is left empty, doSuperResolution is called synchronously, and the result is output through the second parameter. This function returns the result code.
ImageResult result = new ImageResult();
int resultCode = superResolution.doSuperResolution(image, result, visionCallback);
if (resultCode == 700) {
Log.d(TAG, "Wait for result.");
return;
} else if (resultCode != 0) {
Log.e(TAG, "Failed to run super-resolution, return : " + resultCode);
mTxtViewResult.setText("Failed to run SISR!");
return;
}
if (result == null) {
Log.e(TAG, "Result is null!");
mTxtViewResult.setText("SISR result is null!");
return;
}
if (result.getBitmap() == null) {
Log.e(TAG, "Result bitmap is null!");
return;
}