Using "get" to save pictures, but they come up in color

I wrote this event triggered picture saving sketch. I want to put the pics in the tenser flow later.
I have 2 cameras connected in the same time and after I bring the video in, I turn it into grayscale right away with the filter.
Then, when I get the right signal from the arduino, I save the two pics in sequential order.
The video shows as grayscale, but the pics are saved as color.

What to do?
Thanks a lot , here is the code:

BTW, is there a way to run tenser flow in Processing?

 // size(1900, 1000, JAVA2D);
 size(1300, 610);
 
  createGUI();
  customGUI();
  streamer = new AP_Sync(this, "COM5", 115200);
  String[] cameras = Capture.list();
  if (cameras == null) {
    println("Failed to retrieve the list of available cameras, will try the default...");
    video = new Capture(this, 640, 480);
    video2 = new Capture(this, 640, 480);
  } 
  if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  } else 

  {
    println("Available cameras:");
    printArray(cameras);


    video = new Capture(this, "name=USB Camera,size=640x480,fps=30");
    video2 = new Capture(this, "name=USB Camera-Video2,size=640x480,fps=30");

    video.start();
    video2.start();
  }


  font = loadFont("AgencyFB-Bold-200.vlw");
  frameRate (30);
}

void captureEvent(Capture video) {

    video.read();
    video2.read();

}


void draw() {
  background(bk); 
  

  video.loadPixels();
  video2.loadPixels();
  image(video, 0, 0);
  image(video2, 660, 0);
  filter(GRAY);
  PImage videoCropped = video.get(); 
  PImage video2Cropped = video2.get(); 
   //   filter(THRESHOLD,.1);

  stroke(w);
  strokeWeight(3);
  line (320, 0, 320, 500);

 //println(Aquire+" is Aquire");
  textFont(font, 25); 
  fill(w);
    if (Ready ==1)// comes from the Arduino
  {  
    Aquire= false;
   delay (100);
   Seq=Seq +1;
   String Next = str(Seq);
   
   String VideoFileNameFinalV1 = "GoodPotsV1/"+ Next+"_GoodPotsV1.png";
   String VideoFileNameFinalV2 = "GoodPotsV2/"+ Next+"_GoodPotsV2.png";
   videoCropped.save(VideoFileNameFinalV1);
   
   video2Cropped.save(VideoFileNameFinalV2);
   delay (500);
   
  text("POT PRESENT", 10, 790);
  }
  else
  { // Aquire= true;
   text("POT ABSENT", 10, 790);
  }
   
  text("VIDEO 1 ", 10, 510 );
 text("VIDEO 2 ", 660, 510 );
  
 
  /*
   */
}// end of draw

after 26 posts still can not post code in

</>

formatter?

you expect

filter(GRAY)

to change the PImage called video ( video2)
but it does only change the display

but

video.loadPixels();
video.filter(GRAY);
image(video, 0, 0);
if (Ready ==1) video.save(VideoFileNameFinalV1);

might work

YEY, that worked , thanks a lot,

Sorry about not using brackets, I will in the future,

There is no explicit way to attach a file, like the arduino forum has.

Thanks again, you’re a genius,.

Mitch

sorry, but i ask you to repair it now.

( i know who is to blame, last 3 times a moderator did it FOR YOU! LOL )

I was not able to edit the first post, sorry, I am not ill intended. How can I fix it?

I have another question. I am trying to delay the saving of the video2 picture by 100ms.
That would position my part in a more optimal place.
The delay simply does not happen. Even if I put 2 seconds, nothing seems to be different. The acquisition is at the same time. Any ideas?

The final delay of 500ms works fine. ( I use that so the part is clear off the conveyor )

Thanks

if (Ready ==1)// comes from the Arduino

{



Seq=Seq +1;

String Next = str(Seq);

videoCropped.save(VideoFileNameFinalV1);
delay (100);
video2Cropped.save(VideoFileNameFinalV2);
delay (500);


pls use the
2018-12-29_09-58-14_snap_cut
to edit your old post
and use

</>

for repaste good formatted ([ctrl][t]) code

1 Like

I got it, thanks for the guidance.
Any ideas on my delay problem?

1 Like

delay is useful for Arduino, but it’s not the proper way to temporize in Processing.
Use frameCount or millis() instead, depending on your need.
In this case, if you want something wich work like delay(), do something like that :

void draw() {
  while ( millis() < i) {
  //what you want to display / change for example : 
background( 0 + x) 
  }
  i += 1000; // for a delay of 1 second
x += 20
}

besides @Pr0tonX already give you a timer,
some words about my understanding,
looks like any ( 5 hour) delay of saving that ( same ) picture
is not what you need.

you want save a LATER picture.
and that is why any delay ( and at that code position ) not does the job.
so instead there you must START a timer.
like with
startT = millis();
and when the timer is finished

void myTimer() {
  if ( millis() >= startT + deltaT ) {
    // do what needs to be done
  }
}

do the

videoimage.save(picturefilename);

on the then current image.

i hope that wording helped little bit.

( pls experiment with the timer code in a extra little tool
like using many println("timer: "+i); )