We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have successfully created a string with the files of a fold of my choice, however I receive an error. Please see attached image.
import gab.opencv.*;
import java.awt.Rectangle;
OpenCV opencv;
Rectangle[] faces;
int filenumber = 0;
int croppedimage = 0;
File dir = new File("/Users/JPHS1/Desktop/New");
String[] imglist = dir.list();
void setup() {
for (String name1 : imglist) {
setupSmall(name1);
drawSmall();
}
//
}
void draw() {
// empty
}
// -----------------------------------------
void setupSmall(String name1) {
a
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
faces = opencv.detect();
}
void drawSmall() {
for (int i = 0; i < faces.length; i++) {
rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
copy(opencv.getInput(),faces[i].x, faces[i].y, faces[i].width, faces[i].height, 0,0, faces[i].width, faces[i].height);
if (filenumber < 3) {
line(filenumber, 0, filenumber, 100);
filenumber = filenumber + 1;
} else {
noLoop();
}
PImage sectionOfScreen = get(0,0, faces[i].width, faces[i].height);
sectionOfScreen.save("cropped" + filenumber);
}
}
Comments
The error message is unreadable: don't show screenshots, copy & paste the error here instead. Don't forget to point to the line where the error happens. (Looks like it disappeared from the listing you gave!)
By squinting a lot, I can guess, more than read, the code and error...
You pass a file name, not its full path. Use dir.listFiles() instead, and use file.getAbsolutePath() to get the full path.
Note that if you had println() the parameter, you could have seen the problem yourself... (Or not, if you supposed OpenCV would guess the path...)
I am still quite confused. Within the code below, where should I use dir.listFiles()? Where I have it now? Also, where should file.getAbsolutePath() be?
Currently with the code below, I recieve the error "Cannot convert from File[] to String[]"
If you looked at the reference I pointed to, you will see that listFiles() returns an array of File objects, not of String. Which is exactly what the error message says...
Thus code should look like: