We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I recently started working with processing and I have two questions that I really need help with.
The two things I need to accomplish are this:
Currently I having trouble saving just what I copy. I only seem to save the entire window.
Rectangle[] faces;
int filenumber = 0;
int croppedimage = 0;
void setup() {
opencv = new OpenCV(this, "test2.jpg");
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
faces = opencv.detect();
size(opencv.width, opencv.height);
}
void draw() {
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();
}
//croppedimage = get(opencv.width*2,opencv.width*2, opencv.height, opencv.height);
//image(croppedimage,0,0);
saveFrame("cropped" + filenumber);
}
}
Answers
I do batch of images in IrfanView
it's free and it's great
also, please go back and format your code: 2 empty lines before, select code, click C in the small command bar
Sorry about that! Within IrfanView, I am not able to crop based on faces detected? That is why I am writing this program.
To rephrase, how do can I save what I copy() into an image file.
not tested.............
Wonderful! It worked perfectly... In the code below, once I have assigned the files to that string dir.list, can I pass them through what I just wrote? Then have the program run until all files have been cropped?
I think so
think of your former sketch with setup() and draw() as the kernel
around this kernel we want to build our new frame
as you guessed, put the stuff of setup and draw in setupSmall and drawSmall
and then proceed
not tested
[EDITED]
Chrisir ;-)
I definitely see what you are saying and I understand, but I do not understand how you can have two void setups and two void draws? Are you saying that my 'kernel' should reference the setupSmall and drawSmall?
something like this
from setup you call setupSmall and drawSmall
sorry, I'm off now
I corrected my posts
"name1" is where i will place the string I created from my folder of jpgs, but what does "list" identify?
Deleted your last message, since you made a separate thread from it. Avoid duplicates. (But making a new thread for a new problem is a good idea.)
Didn't this work?
It should work.
What it does:
list is the same array as in your sketch.....
;-)
I had to change name1 to the string that holds the file names, correct? And when I do so, it gives me a NullPointerException. PhilLho had said that I needed to supply OpenCV with the full file path.
I had to change name1 to the string that holds the file names, correct?
that's my line:
it depends on what list holds (names of files?)
anyway, when all images are in the same folder
or when the in the data folder of your sketch
;-)
I am sadly still having trouble. I keep receiving a NullPointerException on "for(String name1: imglist)"
For clarification, I am attempting to access a folder of jpgs.
Also, Chrisir
for (String name1 : list) {
List is not any type of predetermined function in processing?
Hello!
Sorry, I don't know what you are asking at the moment.
As I said, list is the name of an array that you came up with in the first place:
see above.
this:
is just a short way to write a for-loop. Sorry, I didn't mean to confuse you with that.
here is an example sketch to show this new
for (String var : list)
approach :that's the same as
so, just use that to loop to all the files you got in your list (add the path somehow).
during the loop call setupSmall and and drawSmall as described.
Please ask again if you need help.
Chrisir ;-)
You are amazing, and thank you so much for your help. Just to clarify, here is where I am at with my code. I have two sections.
Section #1 : Works perfectly on ONE image, whatever "test.jpg" is.
Section #2 : Implementing loop
So now i have fragment[i] storing the files. How can I properly move this loop into the code in section 1? I believe I would then have a working application. I may also need to get the full file paths instead of just the names.
ok, it's good to break the problem down into 2 independent sections
first the path question:
does this work:
?
when it works, path is ok.
you should see 20 images come up
now for the joining of the sections
I answered that a few times but never mind
Well it appears to work, but when I
println(fragment[i]);
it outputs thisIt also does not display any images.
it totally doesn't work
what does it say in the direct window...?
do you have the 20 images in data folder of your sketch as 1.jpg, 2.jpg etc.?
Damn.. I think I got it. Well, you got it, but I hit run.
It is extremely inaccurate though, haha. OpenCV's face detection is not too hot. It recognized a hub cap, also my code makes it think that it has to output and image for everything, not only when it detects a 'face'.
here...........
Wonderful... now just to find a way to integrate this.
just replace line 50 with
what is this?
wouldn't that be enough
filenumber = filenumber + 1;
Yes you are quite right about the simplification of that loop. I will implement the two together now.