如何将OpenCV(JavaCV)训练过的人脸图片保存到数据库?
最近,我完成了一个关于使用JavaCV进行人脸识别的项目。它会将人脸保存到计算机目录,但我想将这些人脸保存到像SQLite这样的RDBMs中,欢迎使用MySQL 将图像保存到计算机目录的代码如何将OpenCV(JavaCV)训练过的人脸图片保存到数据库?,java,mysql,opencv,javacv,Java,Mysql,Opencv,Javacv,最近,我完成了一个关于使用JavaCV进行人脸识别的项目。它会将人脸保存到计算机目录,但我想将这些人脸保存到像SQLite这样的RDBMs中,欢迎使用MySQL 将图像保存到计算机目录的代码 private String createPictureFilePathName(File dir) { File file = new File(dir.getPath() + "/image-0.png"); int counter = 1; while (file.exists
private String createPictureFilePathName(File dir) {
File file = new File(dir.getPath() + "/image-0.png");
int counter = 1;
while (file.exists()) {
file = new File(dir.getPath() + "/image-" + counter + ".png");
counter++;
}
return file.getPath();
}
private static JFileChooser initPictureDirChooser() {
JFileChooser chooser = new JFileChooser();
chooser.setAcceptAllFileFilterUsed(false);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setCurrentDirectory(new File(System.getProperty("user.home")).getAbsoluteFile());
return chooser;
}
是否有可能将图像保存到数据库?获取文件的输入流,并使用preparedstatement将其作为blob保存到db中 示例代码:
public boolean saveFile(File file) throws Exception{
boolean completed = false;
ConnectionManager conn = new ConnectionManager();
try {
PreparedStatement statement = conn.getConnection().prepareStatement("QUERY_TO_INSERT_FILE");
statement.setBlob(1, file.getInputStream());
statement.execute();
conn.commit();
completed = true;
} catch (SQLException e) {
conn.rollbackQuietly();
e.printStackTrace();
throw e;
} catch (ClassNotFoundException e) {
e.printStackTrace();
}finally{
conn.close();
}
return completed;
}
获取文件的输入流,并使用preparedstatement将其作为blob保存到db中 示例代码:
public boolean saveFile(File file) throws Exception{
boolean completed = false;
ConnectionManager conn = new ConnectionManager();
try {
PreparedStatement statement = conn.getConnection().prepareStatement("QUERY_TO_INSERT_FILE");
statement.setBlob(1, file.getInputStream());
statement.execute();
conn.commit();
completed = true;
} catch (SQLException e) {
conn.rollbackQuietly();
e.printStackTrace();
throw e;
} catch (ClassNotFoundException e) {
e.printStackTrace();
}finally{
conn.close();
}
return completed;
}
获取文件的输入流,并使用preparedstatement将其作为blob保存到db中。@AndyJones我找到了一些教程:和。很快我就可以实现从繁忙的日程中解脱出来的时间。@webcoder不使用InputStream也可以实现吗?基本上,我想捕获人脸并将其直接保存到数据库中。获取文件的输入流并使用preparedstatement将其作为blob保存到db中。@AndyJones我找到了一些教程:和。很快我就可以实现从繁忙的日程中解脱出来的时间。@webcoder不使用InputStream也可以实现吗?基本上,我想捕捉人脸并将其直接保存到数据库中。