I think it would be easier to actually combine sketch 1 and sketch 2 into one sketch file.
Well, I've made those 4 util functions inside the original sketch 1 originally.
But b/c you were asking for a separate sketch 2, I've posted them separated from sketch 1.
This is how I actually have them unified w/ sketch 1 here: :(|)
Oh, I misunderstood you, I get it now. I was trying to do it from within sketch 2 not sketch 1 and I thought you were doing the same on your end, my bad.
So now if I move sketch 2 inside the sketch 1 folder, it should pick out the segments from the same data folder if I ask it to using the Pimage, correct? http://imgur.com/a/vE4qQ
Is what I have now.
I was thinking this https://www.gicentre.net/utils/multiwindow
might help to resolve that error, im still looking into it though.
I tried installing the multisketch, but I think its missing its own library or its not available to download for some reason. The "Two sketches embedded in a single window" looked good. I've found the archive here: https://www.gicentre.net/utils/archive/
Version 3.4 mentions "The multisketch package (embedded sketches and slideshow) has been temporarily removed as it relied on Java-specific implementation of Processing 2 (the AWT)."
But every version before 3.4 includes it. How would I install it manually or do I need processing 2 instead of 3?
I've moved this project to a macbook to see if it would run on a mac, and obviously I knew I'd run into a few errors.
The error im getting using sketch 1 is "COMMAND ERROR: Cannot run program "opencd": error=2, No such file or directory" https://pastebin.com/ZMH7Vp80
I installed the numpy, scipy and matplotlib on my mac in order for it to run.
Cheers
Ah-ha!
Ok...
So im getting a different error now instead:
"the files /Users/J/cd, /Users/J/&&, and /Users/J/Python do not exist"
Is this just a directory mishap on my part?
Recall that this sketch was originally customized to use specific subfolder inside subfolder "data/".
For example, The Python's script should be here: static final String PY_DIR = "scripts/";
And the source images: static final String PICS_DIR = "images/";
If you can't mime the same path names as it was in Windows, you're gonna need to modify the sketch's constants in order to match your current environment.
Yep its all within the same folder as before in "sketch 1" script is in scripts, etc..is it because I have the folder on the desktop, instead of in /Users/J?
In which case, how would I edit v2.0.3 to have it run from the desktop? (sketch 2 is on the desktop as well)
Well thanks so much for the help again to get me this far! Ill ask over @ stackexchange and see what they say, I dont quite understand how I should name the paths.
After searching to find where python is stored I put: usr/bin/python.
It looks like it recognized it, but im still stuck at cd and &&.... any ideas? :{
-I tried without cd and &&, and it said success true, but no segments.
Why would it say that /Users/J/cd doesnt exist?
What it looks like now: https://imgur.com/a/wMr7S
After searching to find where python is stored I put: "usr/bin/python".
AFAIK, if Python is properly installed in the OS, simply invoking "python" is enough to run it. :>
No need to specify its full path b/c it's already registered in the OS' $PATH system variable. :-B
True. Pretty sure I downloaded and set it up right though.. either way, usr/bin/python seemed to make the python error leave.
Im just lost on this "&&", "cd", I think the program is treating these as directories instead of commands.
Wow hard to follow, but I think I get it. Awesome work. https://imgur.com/a/91Jav
I get a success true now, even with it just being "python"
but still no segmentations...would it be because my directory is incorrect within segmenting.py? https://pastebin.com/qgd4eMjN
Right now its /Users/J/Desktop/Sketch2/Data (line 78)
All the segments created from sketch 1 go to sketch 2, just like before.
Maybe its the "r" thats before that line. I forget what that is supposed to represent.
Apparently "f open" is the equivalent for mac: https://stackoverflow.com/questions/3324486/finding-a-files-directory-address-on-a-mac
But its not working like this either..
Thanks. So I just talked to the guy who helped me out with the segmenting.py, and he said it would need to be r'/Users/J/Desktop/sketch2/data'
So the slashes are the other way for mac.
But im still getting "segment folders found 0"
Damn! :(
Yeah I will for sure, right after I figure how to run this sucker on a mac.
So between the two: https://imgur.com/a/Itd7k (windows) https://imgur.com/a/8sHeA (mac)
Is it possible that on the mac its not even recognizing the python script at all?
'segement detected' is part of the python script that should be printed in.
Oh whoops, I missed that you had edited it, my bad. Yep, im using the same segmenting.py, and with windows it works, but on mac it does not. Has to be a directory issue, because I dont think segmenting.py or python is even being called at all.
I just read that macs come with python 2.7 already installed by default.
Update: It may be an error with pythons "pillow", im working on resolving the errors im getting: https://imgur.com/a/tiL4F
after trying to run the segmenting.py from the mac terminal.
Ok after alot of trial and error, new update. By installing anaconda python 2.7 from https://www.anaconda.com/download/#macos
It allows me to run the segmenting.py from the mac terminal like so:
Js-MacBook:~ J$ python /Users/J/Desktop/sketch1/data/scripts/segmenting.py
And outputs the segments right into the sketch 2 folder.
So im not sure why I still cant run sketch1 with the v2.1.2 command, its still not working....but I imagine its some small error in directory, just cant figure it out. https://forum.processing.org/one/topic/send-command-to-terminal-from-processing.html
Maybe this might help, would it be as simple as just executing the terminal or a file to the terminal from within processing?
BtW, I've made some refactoring on it today and committed those changes there on its GitHub repo. L-)
Particularly, I find filename = os.path.join(os.getcwd(), name) possibly problematic. :-S
Well, It's not causing any problems under Windows.
But for the sake of making sure it won't under Mac or Linux, I've changed that code line to this: filename = os.path.isfile(name) and name or os.path.join(os.getcwd(), name)
So I suggest you to re-download my "segmenting.py" and try that out again. O:-)
... would it be as simple as just executing the terminal or a file to the terminal from within processing?
Like I've mentioned already, at least for my "segmenting.py" version, it relies on CWD in order to know where to save the segmented images. :-\"
That's why "Python Command" issues command CD to temporarily change CWD to the sketch's "data/" subfolder before calling "python". :ar!
Yeah I needed to download anaconda python 2.7 in order for all the numpy/scipy libraries to be updated and in the right place on the mac in order for python to run segmenting.py correctly.
Wait, should I pick /desktop as my sketchbook path? It was on /documents like how you have yours. And yeah, totally works on my windows computer like how you have shown.
Yep, tried out the latest segmenting.py unmodified from your github, still nothing.
Im not sure if this is a python problem or a processing problem at this point...very confusing indeed
Like just anaconda...when I ask "which python" in the mac terminal its "/Users/J/anaconda2/bin/python"
I picked 2.7 over 3.6 because I figured it would work with the python 2.7 thats already installed by default on the mac?
Ah, so I literally just have both sketch1+2 on the desktop, so my sketchbook path should be documents, or should be desktop? Im a little confused. It was documents originally
Ok...I got it! https://forum.processing.org/two/discussion/comment/107753#Comment_107753
Basically on a mac if you create an executable file to the terminal that includes the direct path that opens python and the image you are using, it works.
using launch("/Users/J/Desktop/image");
which contains: /Users/J/Desktop/sketch1/data/scripts/segmentation_pipeline.py /Users/J/Desktop/sketch1/data/images/image.jpg
(just means you need to always rename your image that you want segmented "image"
Since this renders sketch 1 obsolete (at least on a mac) I can move everything into one folder, and what I'd like to do is add the image executable into sketch 2 so that I just have the one sketch file which we shall call "sketch" (if you follow).
So how can I add
launch("/Users/J/sketch/image");
to the current version of sketch 2: https://pastebin.com/Y1EThvb3
So that it launches the exectuable image file before the segments are assigned to hand.jpg?
(ill clean all this up after and make it one tidy file)
All I need to know is how can I add launch("/Users/J/sketch/image");
to https://pastebin.com/Y1EThvb3 so that it comes prior to everything else opening.
Ill compile the rest.
1st your PasteBin sketch is painfully mal-indented, very hard to study.
Before pasting any sketch, always use CTRL+T inside the PDE for auto-indentation.
2nd, the way the sketch was coded is that it is the 1 which auto-finds the paths for all source images.
Then those paths are concatenated in 1 String and are sent to the remote ".py" script.
After the ".py" script finishes, the sketch auto-searches inside the output subfolder "data/images/" for those generated segment images.
However, for that to work correctly, the ".py" script needs to be programmed to output the seg images inside the folder the Processing sketch expects it, inside its "data/images/" subfolder.
Sorry about that. Ok to make this alot easier, here it is: https://www.dropbox.com/s/0nis3dustlus581/sketch.zip?dl=0
It works on my mac if I double click the executable "image" it does its thing and the segments are put in data.
Also included in input1 is a palette image file which can colour the segments at random !
So im thinking use
launch("/Users/J/Desktop/sketch/image"); for MAC
and launch("C:\Users\J\Desktop\sketch\image); for WINDOWS
So somehow add both these into the current sketch file.
for windows would be a text file as well that would include:
python C:\Users\J\Desktop\sketch\scripts\segmentation_pipeline.py C:\Users\J\Desktop\sketch\input1\image.jpg
Would that work?
Im looking at the file here on my windows computer now, you can just open the image file in notepad to check it out.
The ".pde" sketch there is exactly the same mal-indented you've posted in PasteBin.
The reason why I've recommended "Command.java" to you is b/c it already handles the whole Process of calling the external file, saving its output in an array, print in red any error messages, and then waitFor() it to end.
If you rather prefer launch() or exec(), you're gonna have to write the code to deal w/ the Process by yourself!
It works on my end though even with the mal-indents?
Right, so im wondering how I can put launch() into the sketch?
It just needs to come beforehand. Ill look into it.
It might be easier this way, then itd just be one entire sketch file which would look really nice.
Basically you'd have two versions of the python segmenting code, one for windows and one for mac, and two executable files, one for windows and one for mac.
I figured launch() could outline
launch("/Users/J/Desktop/sketch/image");
launch("C:\Users\J\Desktop\sketch\image);
but im not sure how the pde could pick which launch or exec to use.
I've updated the dropbox link above to include the windows version of the python code, I just tested it in the command prompt using
C:\Users\J\Desktop\sketch\scripts\segmentation_pipeline.py C:\Users\J\Desktop\sketch\input1\image.jpg
and it works.
I mean I have both working on windows and mac, but for anyone else interested I think having it as one zip file for both mac and win would be neat, otherwise im all set and appreciate all the help.
It works on my end though even with the mal-indents?
Java language doesn't care about indentations, humans do!
I've updated the dropbox link above...
Not every1 likes to download files in order to see some1 else's code.
Post your code folder on GitHub instead.
Folks can study the code and offer changes to it there.
Hey! Just noticed this...what did you change?
I still have both working on windows and mac, my mac is using the terminal version.
Ill try and run this today.
I came up with another idea for this project....adding this: https://github.com/mxgmn/ConvChain/blob/master/README.md
As the pattern creator..instead of loading in patterns, theres already a processing version of it too! https://github.com/buckle2000/ConvChainJava
...we will see..
Answers
Well, I've made those 4 util functions inside the original sketch 1 originally.
But b/c you were asking for a separate sketch 2, I've posted them separated from sketch 1.
This is how I actually have them unified w/ sketch 1 here: :(|)
https://Forum.Processing.org/two/discussion/23324/executing-python-3-code-from-within-processing/p1#Item_38
Oh, I misunderstood you, I get it now. I was trying to do it from within sketch 2 not sketch 1 and I thought you were doing the same on your end, my bad.
So now if I move sketch 2 inside the sketch 1 folder, it should pick out the segments from the same data folder if I ask it to using the Pimage, correct?
http://imgur.com/a/vE4qQ
Is what I have now.
I was thinking this https://www.gicentre.net/utils/multiwindow
might help to resolve that error, im still looking into it though.
I tried installing the multisketch, but I think its missing its own library or its not available to download for some reason. The "Two sketches embedded in a single window" looked good. I've found the archive here: https://www.gicentre.net/utils/archive/
Version 3.4 mentions "The multisketch package (embedded sketches and slideshow) has been temporarily removed as it relied on Java-specific implementation of Processing 2 (the AWT)."
But every version before 3.4 includes it. How would I install it manually or do I need processing 2 instead of 3?
@kfrajer gave me an answer on the assigning segments part, so sketch 2 is pretty much complete. https://forum.processing.org/two/discussion/comment/102589#Comment_102589
I've moved this project to a macbook to see if it would run on a mac, and obviously I knew I'd run into a few errors.
The error im getting using sketch 1 is "COMMAND ERROR: Cannot run program "opencd": error=2, No such file or directory"
https://pastebin.com/ZMH7Vp80
I installed the numpy, scipy and matplotlib on my mac in order for it to run. Cheers
Before:
Now:
Ah-ha! Ok... So im getting a different error now instead:
"the files /Users/J/cd, /Users/J/&&, and /Users/J/Python do not exist"
Is this just a directory mishap on my part?
static final String PY_DIR = "scripts/";
static final String PICS_DIR = "images/";
Yep its all within the same folder as before in "sketch 1" script is in scripts, etc..is it because I have the folder on the desktop, instead of in /Users/J? In which case, how would I edit v2.0.3 to have it run from the desktop? (sketch 2 is on the desktop as well)
Problem is, I dunno anything about how MacOS organizes a user's folders. Can't help ya w/ that! :(
Well thanks so much for the help again to get me this far! Ill ask over @ stackexchange and see what they say, I dont quite understand how I should name the paths.
After searching to find where python is stored I put: usr/bin/python.
It looks like it recognized it, but im still stuck at cd and &&.... any ideas? :{
-I tried without cd and &&, and it said success true, but no segments.
Why would it say that /Users/J/cd doesnt exist?
What it looks like now: https://imgur.com/a/wMr7S
AFAIK, if Python is properly installed in the OS, simply invoking "python" is enough to run it. :>
No need to specify its full path b/c it's already registered in the OS' $PATH system variable. :-B
https://en.Wikipedia.org/wiki/PATH_(variable)
True. Pretty sure I downloaded and set it up right though.. either way, usr/bin/python seemed to make the python error leave.
Im just lost on this "&&", "cd", I think the program is treating these as directories instead of commands.
Before:
Now:
Given I don't have a Mac, dunno whether the new fix is gonna work... :|
Wow hard to follow, but I think I get it. Awesome work.
https://imgur.com/a/91Jav
I get a success true now, even with it just being "python"
but still no segmentations...would it be because my directory is incorrect within segmenting.py?
https://pastebin.com/qgd4eMjN
Right now its /Users/J/Desktop/Sketch2/Data (line 78)
All the segments created from sketch 1 go to sketch 2, just like before.
Maybe its the "r" thats before that line. I forget what that is supposed to represent.
Apparently "f open" is the equivalent for mac:
https://stackoverflow.com/questions/3324486/finding-a-files-directory-address-on-a-mac
But its not working like this either..
I'm just gonna post the "segmenting.py" version I've been using all along: L-)
https://GitHub.com/GoToLoop/CenturyOfTheSun/blob/master/segmenting.py
Thanks. So I just talked to the guy who helped me out with the segmenting.py, and he said it would need to be r'/Users/J/Desktop/sketch2/data'
So the slashes are the other way for mac.
But im still getting "segment folders found 0"
Damn! :(
Why don't you publish the whole program at GitHub? Much better to visualize: *-:)
https://GitHub.com/
Yeah I will for sure, right after I figure how to run this sucker on a mac.
So between the two:
https://imgur.com/a/Itd7k (windows)
https://imgur.com/a/8sHeA (mac)
Is it possible that on the mac its not even recognizing the python script at all?
'segement detected' is part of the python script that should be printed in.
According to those 2 pictures, neither of them are using the latest Python Command (v2.1.2) I've reposted here! [-(
And I recommend to use my "segmenting.py" version from the link I've already posted here, which I know that it at least works under Windows .
Oh whoops, I missed that you had edited it, my bad. Yep, im using the same segmenting.py, and with windows it works, but on mac it does not. Has to be a directory issue, because I dont think segmenting.py or python is even being called at all.
I just read that macs come with python 2.7 already installed by default.
Update: It may be an error with pythons "pillow", im working on resolving the errors im getting: https://imgur.com/a/tiL4F
after trying to run the segmenting.py from the mac terminal.
Ok after alot of trial and error, new update. By installing anaconda python 2.7 from https://www.anaconda.com/download/#macos
It allows me to run the segmenting.py from the mac terminal like so:
Js-MacBook:~ J$ python /Users/J/Desktop/sketch1/data/scripts/segmenting.py
And outputs the segments right into the sketch 2 folder.
So im not sure why I still cant run sketch1 with the v2.1.2 command, its still not working....but I imagine its some small error in directory, just cant figure it out.
https://forum.processing.org/one/topic/send-command-to-terminal-from-processing.html
Maybe this might help, would it be as simple as just executing the terminal or a file to the terminal from within processing?
Under Windows you were using vanilla 64-bit Python 3.6 instead.
According to the path above, I wonder whether you've directly picked system folder "Desktop/" as your sketchbook path? :-/
In my Windows environment here, I've created a subfolder called "P3/" under "Documents/Sources/", and chosen that as my PDE's sketchbook location.
Have you also tried my "segmenting.py" version from https://GitHub.com/GoToLoop/CenturyOfTheSun/blob/master/segmenting.py unmodified?
BtW, I've made some refactoring on it today and committed those changes there on its GitHub repo. L-)
Particularly, I find
filename = os.path.join(os.getcwd(), name)
possibly problematic. :-SWell, It's not causing any problems under Windows.
But for the sake of making sure it won't under Mac or Linux, I've changed that code line to this:
filename = os.path.isfile(name) and name or os.path.join(os.getcwd(), name)
So I suggest you to re-download my "segmenting.py" and try that out again. O:-)
Like I've mentioned already, at least for my "segmenting.py" version, it relies on CWD in order to know where to save the segmented images. :-\"
That's why "Python Command" issues command CD to temporarily change CWD to the sketch's "data/" subfolder before calling "python". :ar!
Here's my "Python Command"'s output under Windows, having "test.jpg" & "water_coins.jpg" inside subfolder "data/images/": :(|)
Yeah I needed to download anaconda python 2.7 in order for all the numpy/scipy libraries to be updated and in the right place on the mac in order for python to run segmenting.py correctly.
Wait, should I pick /desktop as my sketchbook path? It was on /documents like how you have yours. And yeah, totally works on my windows computer like how you have shown.
Yep, tried out the latest segmenting.py unmodified from your github, still nothing.
Im not sure if this is a python problem or a processing problem at this point...very confusing indeed
Still why have you picked 2.7 over 3.6? 8-X
Also, I thought that Anaconda's Python isn't named "python". Have you checked that out? :-SS
IMO nope! But it seems like it's your actual current sketchbook path according to the output you've posted here. ~:>
Like just anaconda...when I ask "which python" in the mac terminal its "/Users/J/anaconda2/bin/python"
I picked 2.7 over 3.6 because I figured it would work with the python 2.7 thats already installed by default on the mac?
Ah, so I literally just have both sketch1+2 on the desktop, so my sketchbook path should be documents, or should be desktop? Im a little confused. It was documents originally
Sketches should ideally go into sketchbook's folder path. 8-|
Anaconda doesn't use any existing installed Python. #-o
AFAIK, Anaconda hacks the system's path to point to its own Python instead. :ar!
Regardless, that's a good thing that when issuing "python" in the terminal, it runs Anaconda's now. >-)
Ok...I got it! https://forum.processing.org/two/discussion/comment/107753#Comment_107753
Basically on a mac if you create an executable file to the terminal that includes the direct path that opens python and the image you are using, it works.
using launch("/Users/J/Desktop/image");
which contains: /Users/J/Desktop/sketch1/data/scripts/segmentation_pipeline.py /Users/J/Desktop/sketch1/data/images/image.jpg
(just means you need to always rename your image that you want segmented "image"
Since this renders sketch 1 obsolete (at least on a mac) I can move everything into one folder, and what I'd like to do is add the image executable into sketch 2 so that I just have the one sketch file which we shall call "sketch" (if you follow).
So how can I add launch("/Users/J/sketch/image");
to the current version of sketch 2: https://pastebin.com/Y1EThvb3
So that it launches the exectuable image file before the segments are assigned to hand.jpg?
(ill clean all this up after and make it one tidy file)
All I need to know is how can I add launch("/Users/J/sketch/image");
to https://pastebin.com/Y1EThvb3 so that it comes prior to everything else opening.
Ill compile the rest.
Sorry about that. Ok to make this alot easier, here it is: https://www.dropbox.com/s/0nis3dustlus581/sketch.zip?dl=0
It works on my mac if I double click the executable "image" it does its thing and the segments are put in data.
Also included in input1 is a palette image file which can colour the segments at random !
So im thinking use launch("/Users/J/Desktop/sketch/image"); for MAC
and launch("C:\Users\J\Desktop\sketch\image); for WINDOWS
So somehow add both these into the current sketch file.
for windows would be a text file as well that would include:
python C:\Users\J\Desktop\sketch\scripts\segmentation_pipeline.py C:\Users\J\Desktop\sketch\input1\image.jpg
Would that work?
Im looking at the file here on my windows computer now, you can just open the image file in notepad to check it out.
https://GitHub.com/GoToLoop/command/blob/patch-1/src/deadpixel/command/Command.java
It works on my end though even with the mal-indents?
Right, so im wondering how I can put launch() into the sketch?
It just needs to come beforehand. Ill look into it.
It might be easier this way, then itd just be one entire sketch file which would look really nice.
Basically you'd have two versions of the python segmenting code, one for windows and one for mac, and two executable files, one for windows and one for mac.
I figured launch() could outline
launch("/Users/J/Desktop/sketch/image");
launch("C:\Users\J\Desktop\sketch\image);
but im not sure how the pde could pick which launch or exec to use.
I've updated the dropbox link above to include the windows version of the python code, I just tested it in the command prompt using
C:\Users\J\Desktop\sketch\scripts\segmentation_pipeline.py C:\Users\J\Desktop\sketch\input1\image.jpg
and it works.
I mean I have both working on windows and mac, but for anyone else interested I think having it as one zip file for both mac and win would be neat, otherwise im all set and appreciate all the help.
Java language doesn't care about indentations, humans do!
Not every1 likes to download files in order to see some1 else's code.
Post your code folder on GitHub instead.
Folks can study the code and offer changes to it there.
Hey! Just noticed this...what did you change?
I still have both working on windows and mac, my mac is using the terminal version.
Ill try and run this today.
I came up with another idea for this project....adding this: https://github.com/mxgmn/ConvChain/blob/master/README.md
As the pattern creator..instead of loading in patterns, theres already a processing version of it too! https://github.com/buckle2000/ConvChainJava
...we will see..
That's merely the corresponding Python Mode version. :-\"
Posted it for completeness' sake, heheh. :P
Ah, very nice!