我想从https://eaglesky.github.io/2015/12/26/HandGestureRecognition/修改应用程序。 它是识别手语的应用程序。当我添加新手势时,它将转到文件名为1,2,3,4,5.jpg的mydataset文件夹,依此类推。我想要的是在保存手势之前先创建自定义名称。
已编辑:完整代码在上面的链接中,位于app> java> com.example.newdemo> MainActivity
这是代码
boolean savePicture()
{
Mat img;
if (((mode == BACKGROUND_MODE) || (mode == SAMPLE_MODE)
|| (mode == TRAIN_REC_MODE)) || (mode == ADD_MODE) ||
(mode == TEST_MODE)) {
Imgproc.cvtColor(rgbaMat, bgrMat, Imgproc.COLOR_RGBA2BGR, 3);
img = bgrMat;
} else if (mode == DETECTION_MODE) {
img = binMat;
} else
img = null;
if (img != null) {
if (!isExternalStorageWritable()) {
// Toast.makeText(getApplicationContext(), "External storage is not writable!", Toast.LENGTH_SHORT).show();
return false;
}
File path;
String filename;
if (mode != ADD_MODE) {
path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
filename = "image_" + imgNum + ".jpg";
} else {
path = storeFolder;
filename = curLabel + ".jpg";
}
imgNum++;
File file = new File(path, filename);
Boolean bool = false;
filename = file.toString();
bool = Highgui.imwrite(filename, img);
if (bool == true) {
// Toast.makeText(getApplicationContext(), "Saved as " + filename, Toast.LENGTH_SHORT).show();
Log.d(TAG, "Succeed writing image to" + filename);
} else
Log.d(TAG, "Fail writing image to external storage");
return bool;
}
return false;
}