# 3d scanner with Arduino and laser pointer

**URL:** <https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360>\
**Category:** Project Guidance\
**Created:** [May 29, 2021, 5:51pm UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360 "2021-05-29T17:51:33Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [June 5, 2021, 9:14pm UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/41 "2021-06-05T21:14:26Z")

</div>

Its on @noel’s github

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [June 5, 2021, 9:21pm UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/42 "2021-06-05T21:21:23Z")

</div>

this ??

```auto
import android.app.Activity; 
import android.content.Intent; 
import android.provider.MediaStore; 

public static final int LAUNCH_CAM = 1; 

public void setup() { 
  orientation(LANDSCAPE); 
  Intent intent= new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA); 
  getActivity().startActivityForResult(intent, LAUNCH_CAM);
}

```

## [Android-java-code-utilities-widgets-for-Processing-for-Android](https://github.com/EmmanuelPil/Android-java-code-utilities-widgets-for-Processing-for-Android)/ **Launch camera**

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [June 5, 2021, 9:46pm UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/43 "2021-06-05T21:46:45Z")

</div>

my mistake i thought he posted a video lib on his repo, but it was the sound lib.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [June 6, 2021, 6:55am UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/44 "2021-06-06T06:55:55Z")

</div>

@paulgoux how to use the code ?

```auto
import java.io.BufferedWriter;
import java.io.FileWriter;

String outFilename = "out.txt";

void setup(){
  // Write some text to the file
  for(int i=0; i<10; i++){
    appendTextToFile(outFilename, "Text " + i);
  } 
}

/**
 * Appends text to the end of a text file located in the data directory, 
 * creates the file if it does not exist.
 * Can be used for big files with lots of rows, 
 * existing lines will not be rewritten
 */
void appendTextToFile(String filename, String text){
  File f = new File(dataPath(filename));
  if(!f.exists()){
    createFile(f);
  }
  try {
    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f, true)));
    out.println(text);
    out.close();
  }catch (IOException e){
      e.printStackTrace();
  }
}

/**
 * Creates a new file including all subfolders
 */
void createFile(File f){
  File parentDir = f.getParentFile();
  try{
    parentDir.mkdirs(); 
    f.createNewFile();
  }catch(Exception e){
    e.printStackTrace();
  }
} 

```

```auto
try {
  FileWriter output = new FileWriter("example.csv",true); //the true will append the new data
  output.println("a;b;c;this;that ");
  output.flush();
  output.close();
}
catch(IOException e) {
  println("It Broke :/");
  e.printStackTrace();
}

```

> <https://stackoverflow.com/questions/17010222/how-do-i-append-text-to-a-csv-txt-file-in-processing>

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [June 6, 2021, 8:23am UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/45 "2021-06-06T08:23:34Z")

</div>

> [@Read and write images and text files Android](https://discourse.processing.org/t/read-and-write-images-and-text-files-android/29947):
>
> text saver. Save text to any location in android. Please set the manifest permissions by adding the following file to your sketch folder. AndroidManifest.xml \<?xml version="1.0" encoding="UTF-8"?\> \<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package=""\> \<uses-sdk android:minSdkVersion="17" android:targetSdkVersion="28"/\> \<application android:icon="@mipmap/ic\_launcher" android:label=""\> \<activity android:n…

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [June 6, 2021, 8:37am UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/46 "2021-06-06T08:37:41Z")

</div>

As for video @noel has a video sketch.

> <https://github.com/EmmanuelPil/Android-java-code-utilities-widgets-for-Processing-for-Android/blob/master/Video%20player>

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [June 6, 2021, 9:39am UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/47 "2021-06-06T09:39:47Z")

</div>

Hi @paulgoux this code how to save image from ketai camera ?

 ![Screenshot_2021-06-06-12-32-09-368](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/1587435d718c1e8e765dd1ec978570aaaa2c408b.jpeg)

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [June 6, 2021, 9:41am UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/48 "2021-06-06T09:41:33Z")

</div>

You just have to set the fileoutput.img variable.  
Ketai produces an image for the cam stream, simply called cam, so set img to cam.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [June 6, 2021, 9:49am UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/49 "2021-06-06T09:49:29Z")

</div>

I did not understand

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [June 6, 2021, 9:56am UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/50 "2021-06-06T09:56:23Z")

</div>

Theres a variable in the fileoutput class called img. Thats what it uses to save. If you want to save something else such as the ketai class variable cam which is a pgraphics object then you have to set img to cam.

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [June 6, 2021, 10:00am UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/51 "2021-06-06T10:00:44Z")

</div>

I meant in the imageSaver class

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [June 6, 2021, 10:03am UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/52 "2021-06-06T10:03:05Z")

</div>

All img set to cam ?

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [June 6, 2021, 10:06am UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/53 "2021-06-06T10:06:21Z")

</div>

What do you mean all.

Just write

fileOutput f = new fileOutput();  
f.img = cam

This will have to be done in draw or img wont have the most recent camera image.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [June 6, 2021, 10:24am UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/54 "2021-06-06T10:24:10Z")

</div>

> [@paulgoux](#):
>
> fileOutput f = new fileOutput();

I can not find this or maybe I am still not following with you

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [June 6, 2021, 10:27am UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/55 "2021-06-06T10:27:25Z")

</div>

Sorry again this needs to be the image saver.

But please look at the code ive shared.

```auto
class imageSaver{
  Permission wstorage,rstorage;
  Activity act;
  PApplet p;
  int counter = -1,maxImageCount;
  boolean imageSaved,mdown;
  String folderName = "MyImageFolder",fileName,ext,absolutePath;
  String imageFile = "MyImage.jpg";

// see this variable is the one saved
  PImage img;
  File file,file2;
  
  imageSaver(PApplet applet){
    p = applet;
    wstorage = new Permission(p,"WRITE_EXTERNAL_STORAGE");
    act = p.getActivity();
    getExt(imageFile);
  };
  
  imageSaver(PApplet applet,String s1, String s2){
    folderName = s1;
    imageFi

```

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [June 6, 2021, 10:46am UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/56 "2021-06-06T10:46:57Z")

</div>

alternatively using the following sketch

```auto
import android.os.Environment;
import android.Manifest; 
import android.content.pm.PackageManager; 
import android.os.Build; 
import android.os.Build.VERSION_CODES; 
import processing.core.PConstants;
import android.app.Activity; 

PImage img;
Activity activity; 
boolean image_saved;
boolean permissions_granted;

// Folowing file name is the folder you save your image file in.
// If it does not exist it will be created automatically
String folder_name = "MyImageFolder";

// Folowing string is the name of your image file
// Be sure to include extension.
String image_file = "MyImage.jpg";
Permission wstorage,rstorage;
void setup() {
  wstorage = new Permission(this,"WRITE_EXTERNAL_STORAGE");
  rstorage = new Permission(this,"READ_EXTERNAL_STORAGE");
  size(displayWidth, displayHeight);
  background(0, 0, 200); 
  rectMode(CENTER);
  rect(width/2, height/2, width, height/2);
  textAlign(CENTER);
  String str = "Click to save an image.";
  textSize(12);
  float twf = width/textWidth(str);
  textSize(8*twf);
  fill(0);
  text(str, width/2, height/2);
//rather than setting img here you set it in draw
  //img = get();
  //img.save(
};

void draw() {
//note you have to set it to whatever your ketaicamera instance is called + ".cam"
img = ketai.cam;
  if (image_saved) {
    background(0, 0, 200);
    fill(255);
    text("Image saved.", width/2, height/2);
  } 
};

void mousePressed() {
  saveMyImage(folder_name, image_file);
};

void saveMyImage(String sf, String tf) { 
  try { 
    String absolute_path = new String(Environment.getExternalStorageDirectory().getAbsolutePath()); 
    File file = new File(absolute_path+"/"+sf); 
    //println(file);
    if (!file.exists()) { 
      boolean success = true; 
      success = file.mkdirs();
      if(success){
        save(file+"/"+tf);
        image_saved = true;
        println("File saved successfully.");
        println("Path",absolute_path,"File",file);
      }
      else {
        println("no File");
        println("Path",absolute_path,"File",file);
      }
    } 
    
    
  } 
  catch (Exception e) { 
    //println("Error while saving file: " + e);
  }
};

```

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [June 6, 2021, 11:44am UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/57 "2021-06-06T11:44:41Z")

</div>

@paulgoux thanks I am going to try your code at night

This is the first printed scan

 ![IMG_20210606_143933](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/00113ab01d376ab179f3bfe64f439a8124c0c1dc.jpeg)

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [June 9, 2021, 4:16pm UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/58 "2021-06-09T16:16:42Z")

</div>

@paulgoux

hi

this ketai on android

```auto
import android.os.Environment;
import ketai.camera.*;
//import processing.video.*;
//Capture video ;
KetaiCamera video;
int Repetition; 
float pics_per_rev = 20; 

void setup() {
  size(640, 480);
  orientation(LANDSCAPE);
  video= new KetaiCamera(this, 600, 480, 30);
 // video= new Capture(this, 600, 480, 30);
 // video.setCameraID(0);                                        
  imageMode(CENTER);
 

  video.start();
}

void draw() {
 // image(video, width/2, height/2, width, height);
  drawUI();                                                   
onCameraPreviewEvent();
}

void drawUI() {                                            
}

void onCameraPreviewEvent() {
  video.read();

  image(video, 0, 0, width, height);
  video.loadPixels();
  delay(2000);
  for (Repetition=0; Repetition<pics_per_rev; Repetition ++) {
    video.read();
    image(video, 0, 0, width, height);
    video.loadPixels();
    for (int n=0; n<video.width*video.height; n++) {
      video.pixels[n]=video.pixels[n];
    }
    video.updatePixels();
    set(20, 20, video);
    String file_name="raw_image-"+nf(Repetition+1, 3)+".png";// this the orginal
    video.save(file_name);
  }
  noLoop();
}

```

how to save images using this code

> [@paulgoux](#):
>
> alternatively using the following sketch
> 
> ```auto
> import android.os.Environment;
> import android.Manifest;
> 
> ```

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [June 9, 2021, 6:52pm UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/59 "2021-06-09T18:52:52Z")

</div>

ive left comments in the code 😉

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [June 9, 2021, 6:58pm UTC](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360/60 "2021-06-09T18:58:29Z")

</div>

thank you i see and read but could not do it that why i asked

edit  
@paulgoux give me some explanation if you pleas

[Previous page](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360.md?page=2)

[Next page](https://discourse.processing.org/t/3d-scanner-with-arduino-and-laser-pointer/30360.md?page=4)
