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

**URL:** https://discourse.processing.org/t/using-get-to-save-pictures-but-they-come-up-in-color/6944
**Category:** Libraries
**Created:** [December 28, 2018, 5:58am UTC](https://discourse.processing.org/t/using-get-to-save-pictures-but-they-come-up-in-color/6944 "2018-12-28T05:58:53Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)
#### Post date: [December 28, 2018, 5:58am UTC](https://discourse.processing.org/t/using-get-to-save-pictures-but-they-come-up-in-color/6944/1 "2018-12-28T05:58:53Z")

</div>

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?

```auto
 // 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

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [December 28, 2018, 8:40am UTC](https://discourse.processing.org/t/using-get-to-save-pictures-but-they-come-up-in-color/6944/2 "2018-12-28T08:40:51Z")

</div>

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

> **[filter() / Reference](https://processing.org/reference/filter_.html)**
>
> Filters the image as defined by one of the following modes: THRESHOLD Converts the image to black and white pixels depending on if they are above or below the threshold defined by the …

but

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

```

might work

---

<div class="post-metadata">

### Author: ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)
#### Post date: [December 28, 2018, 5:47pm UTC](https://discourse.processing.org/t/using-get-to-save-pictures-but-they-come-up-in-color/6944/3 "2018-12-28T17:47:23Z")

</div>

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

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [December 29, 2018, 1:04am UTC](https://discourse.processing.org/t/using-get-to-save-pictures-but-they-come-up-in-color/6944/4 "2018-12-29T01:04:33Z")

</div>

> [@laptophead](#):
>
> Sorry about not using brackets, I will in the future,

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 )

---

<div class="post-metadata">

### Author: ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)
#### Post date: [December 29, 2018, 2:51am UTC](https://discourse.processing.org/t/using-get-to-save-pictures-but-they-come-up-in-color/6944/5 "2018-12-29T02:51:46Z")

</div>

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

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

{

Seq=Seq +1;

String Next = str(Seq);

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

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [December 29, 2018, 3:03am UTC](https://discourse.processing.org/t/using-get-to-save-pictures-but-they-come-up-in-color/6944/6 "2018-12-29T03:03:23Z")

</div>

pls use the  
 ![2018-12-29_09-58-14_snap_cut](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/9836e1f09347212740b9c8a938eefac3e685b4da.png)  
to edit your old post  
and use

```auto
</>

```

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

---

<div class="post-metadata">

### Author: ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)
#### Post date: [December 29, 2018, 4:17pm UTC](https://discourse.processing.org/t/using-get-to-save-pictures-but-they-come-up-in-color/6944/7 "2018-12-29T16:17:06Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Pr0tonX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pr0tonx/32/2590_2.png) [@Pr0tonX](https://discourse.processing.org/u/Pr0tonX)
#### Post date: [December 29, 2018, 4:36pm UTC](https://discourse.processing.org/t/using-get-to-save-pictures-but-they-come-up-in-color/6944/8 "2018-12-29T16:36:55Z")

</div>

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 :

```auto
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
}

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [December 30, 2018, 12:51am UTC](https://discourse.processing.org/t/using-get-to-save-pictures-but-they-come-up-in-color/6944/9 "2018-12-30T00:51:01Z")

</div>

> [@laptophead](#):
>
> Any ideas on my delay problem?

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

```auto
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); )
