I have developed a face recognition application using javaCV and like to put my MySQL DB and Training image set in a to server accomplish a centralized online data set that i can access anywhere , Can anyone suggest me a method to get training images folder for processing in desktop java application
below is the method i pass images for recognition
public int FRecognizer(String path) {
String trainingDir = "C:\\Users\\Kavinda\\Documents\\NetBeansProjects\\Eagle_EYE\\trainingImages";
Mat testImage = imread(path, CV_LOAD_IMAGE_GRAYSCALE);
File root = new File(trainingDir);
FilenameFilter imgFilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
name = name.toLowerCase();
return name.endsWith(".jpg") || name.endsWith(".pgm") || name.endsWith(".png");
}
};
Related
I have a Java program that is able to change the wallpaper taking in input an image using WINAPI.
Everything works fine when I run it inside Eclipse IDE, but when I run the JAR I got the error:
Caused by: java.lang.IllegalArgumentException: URI is not hierarchical
public class Main {
//INIT USER32 for WINAPI
public static interface User32 extends Library {
User32 INSTANCE = (User32) Native.loadLibrary("user32",User32.class,W32APIOptions.DEFAULT_OPTIONS);
boolean SystemParametersInfo (int one, int two, String s ,int three);
}
public static void main(String[] args) throws IOException, URISyntaxException {
//Change wallpaper
System.out.println("Change wallpaper");
URL url = Main.class.getResource("/resources/img.jpg");
File f = new File(url.toURI());
String path = f.getPath();
User32.INSTANCE.SystemParametersInfo(0x0014, 0, path , 1);
}
}
The image is shipped within the JAR, so maybe the error is related to this since the program is not able to correctly read to URL inside the JAR.
Is there a way to solve this?
A jar file is just a compressed file when the resource is bundled as a jar java will be treated as a single file, which means it will not access to your resources.
try using this instead getResourceAsStream(...);
I am using the JSON API - Google API Client Library for Java to access the objects in Google Cloud Storage. I need to create (not upload) an empty folder in the bucket. Google Developer Web Console has that option to creating a directory, but neither the Java API nor the gsutil command has a create folder command. If anybody knows how to do so, please let me know. Thanks in advance...
You can emulate a folder by uploading a zero-sized object with a trailing slash.
As noted in the question comments, Google Cloud Storage is not a filesystem and emulating folders has serious limitations.
I think is better that you create the folder within the file name. For example if you need a folder called images and other one called docs, when you give the name of the object to upload do it in the following way images/name_of_file or docs/name_of_file.
If the name of the file is images/dogImage and you upload that file, you will find in your bucket a folder called images.
I hope to help you and others
This is my Java method to create an empty (emulated) folder:
public static void createFolder(String name) throws IOException {
Channels.newOutputStream(
createFile(name + "/")
).close();
}
public static GcsOutputChannel createFile(String name) throws IOException {
return getService().createOrReplace(
new GcsFilename(getName(), name),
GcsFileOptions.getDefaultInstance()
);
}
private static String name;
public static String getName() {
if (name == null) {
name = AppIdentityServiceFactory.getAppIdentityService().getDefaultGcsBucketName();
}
return name;
}
public static GcsService service;
public static GcsService getService() {
if (service == null) {
service = GcsServiceFactory.createGcsService(
new RetryParams.Builder()
.initialRetryDelayMillis(10)
.retryMaxAttempts(10)
.totalRetryPeriodMillis(15000)
.build());
}
return service;
}
I have this structure in my project:
and my code is simply this:
public class ChapterTwo {
public static void main( String[] args )
{
try {
//File imageFile = new File("../../../../resources/lena.jpg");
String image = ChapterTwo.class.getResource("resources/lena.jpg").toExternalForm();
System.out.println(image);
//MBFImage image = ImageUtilities.readMBF(imageFile);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Now this has been driving me crazy. how hard is it to make java locate an image in a simple directory structure?
I tried:
resources/lena.jpg
/resources/lena.jpg
../resources/lena.jpg
../../../../../resources/lena.jpg
nothing works. When I load the File and call exists() it always returns false. How do I load this image?
PS: My code is just testing code, but you get the idea, I was trying various stuff.
And it is com.foo not com
EDIT:
From the answers:
String imagePath = ChapterTwo.class.getClassLoader().getResource("lena.jpg").toExternalForm();
File imageFile = new File(imagePath);
System.out.println(imageFile.exists());
I get false ....
String image = ChapterTwo.class.getClassLoader().getResource("lena.jpg").getPath();
I am implementing an Applet which needs to access to file system and I need to show to user mock/fake files under mypc or userhome.
There is a way to do it using JFileChooser with FileSystemView:
This is a short example for Windows OS:
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSystemView(new FileSystemView() {
#Override
public File createNewFolder(File containingDir) throws IOException {
//do something, not important here
return null;
}
#Override
public File[] getFiles(File dir, boolean useFileHiding) {
File[] files = super.getFiles(dir, useFileHiding);
// my pc -> desktop -> null
if (dir.getParentFile() == null
|| dir.getParentFile().getParentFile() != null) {
return files;
}
List<File> newFiles = new ArrayList(Arrays.asList(files));
newFiles.add(new File("Custom_File_1"));
newFiles.add(new File("Custom_File_2"));
return newFiles.toArray(new File[newFiles.size()]);
}
});
But the issue is that JFileChooser does not work properly on Mac OS. There is no ability to navigate into any subdirectory, move up from the current directory.
Here is a similar problem:
JFileChooser for directories on the Mac: how to make it not suck? (I switched off DIRECTORIES_ONLY mode, but it did not help)
Now I am trying to use FileDialog, but there is another problem:
I can not find a way to show mock/fake files under mypc or userhome (like FileSystemView).
The question is: Is there an ability to fix JFileChooser in MAC OS? Or add mock/fake files into specific directory using FileDialog?
I'm using eclipse to created an RCP Application, and I'm not being able to load an image because I don't know how to find it in the generated code. I'm going to try to explain my particular issue.
Note: the project is a Game editor, and it is located here: http://chelder86.github.com/ArcadeTongame/
Firstly, this is the project structure:
The next code runs the RCP application correctly inside Eclipse, after changing the Working Workspace in the Eclipse Running Config.
package figures;
(...)
public class Sound extends ImageFigure {
public Sound() {
String picturePath = "src/figures/Sound48.png";
// or String picturePath = "bin/figures/Sound48.png";
Image image = new Image(null, picturePath);
this.setImage(image);
}
}
But it does not work when I create a Product and export it as an RCP Application. I mean, the RCP application works, but it does not load that image.
Note: build.properties has the image checked.
I tried different combinations like these with the same result: java.io.FileNotFoundException, when I run it in Eclipse:
package figures;
(...)
public class Sound extends ImageFigure {
public Sound() {
String picturePath = getClass().getResource("Sound48.png").getPath();
// or String picturePath = this.getClass().getClassLoader().getResource("bin/figures/Sound48.png").getPath();
// or String picturePath = this.getClass().getClassLoader().getResource("figures/Sound48.png").getHost();
// or similars
Image image = new Image(null, picturePath);
this.setImage(image);
}
}
How could I load it correctly?
Thanks for any help! :)
Carlos
Try creating a separate "figures" folder alongside "icons" folder. Put only the image files there, not .java files. Don't forget to add it to the class path and to build.properties. Then something like this should work:
InputStream in = getClass().getResourceAsStream("figures/Sound48.png");
Image image = new Image(Display.getDefault(), in);