# AnySurface



## Cameras

### Consumer USB cameras
Otherwise known as the UVC standard. 
Most platforms can stream the video from a UVC camera, not all have support for changing settings. 

#### Camera Setting Browser Support
| Platform | Supported | Settings |
| :-- | :--: | :--: |
| Android Chrome | ✅ | ✅ |
| Android Firefox | ? | ? |
| Windows Chrome | ✅ | ✅ |
| Windows Firefox | ✅ | ✅ |
| Windows Edge | ✅ | ✅ |
| Linux Chrome | ✅ | partial |
| Linux Firefox | ✅ | partial |
| Mac Chrome | ✅ | ❌ |
| Mac Firefox | ✅ | ❌ |
| iphone | ? | ? |

#### UVC Server
The UVC nodejs server was written to address the shortcomings of the browser support on mac. Runs on port 3456. Known working cameras: Elgato Facecam. Known unsupported: OBSBOT Tiny 4K, HD Webcam C615.

Repository: [https://github.com/RedfishGroup/uvcc-webserver](https://github.com/RedfishGroup/uvcc-webserver)


### IP Cameras
The Pointgrey camera is accessed using a python server. It serves video and settings to port 8080. [https://github.com/RedfishGroup/laser-server/](https://github.com/RedfishGroup/laser-server/)
Other IP cameras, like Axis Cameras, should be should work using the ip camera interface. 

### Classes 
#### CameraInterface
The camera class is the base class for all cameras. It contains an imageLoader and a settingsInterface. The imageLoader is responsible for loading the image and the settingsInterface is responsible for changing the settings of the camera.

TODO example.



```
             +------------------------------------------+
             |                                          |
             |               Camera Interface           |
             |                                          |
             +----+---------------------------------+---+
                  |                                 |
                  |                                 |
+-----------------+---------+                +------+------------------+
|                           |                |                         |
|      Image Loader         |                |  Settings Interface     |
|                           |                |                         |
|                           |                |                         |
| a IPImageLoader           |                | a IP Settings           |
| b UVCImageLoader          |                | b UVC Settings          |
|                           |                | c Browser               |
|                           |                |                         |
+---------------------------+                +-------------------------+

```

#### ImageLoader
The imageLoader is responsible for loading the image from the camera. It is an abstract class and needs to be implemented for each camera type.
* IP Camera: [IPImageLoader.js](./lib/ImageLoaders/IPImageLoader.js) By default looks for http://127.0.0.1:8080/shot.jpg but can be changed.
* UVC Camera: [USBImageLoader.js](./lib/ImageLoaders/USBImageLoader.js) Uses the browser to load the image.

#### SettingsInterface
The settingsInterface is responsible for changing the settings of the camera. It is an abstract class and needs to be implemented for each camera type.
* IP Camera: [IPLaserServerSettingsInterface.js](./lib/SettingsInterfaces/IPLaserServerSettings.js) Used by the Pointgrey camera.
* UVC Camera: [UVCServerSettings.js](./lib/SettingsInterfaces/UVCServerSettings.js) Uses the UVC server to change the settings.
* Browser: [BrowserUSBSettings.js](./lib/SettingsInterfaces/BrowserUSBSettings.js) Uses the browser to change the settings.

#### Dummy Classes
The classes inherit from the dummy classes. 
* [DummyImageLoader.js](./lib/ImageLoaders/DummyImageLoader.js)
* [DummySettingsInterface.js](./lib/SettingsInterfaces/DummyCameraSettingsInterface.js)

## Brightest Point
Find the brightest point. This is historically the most susceptible to noisy lighting. Anything with a 🕷️ emoji is done in the webworker.
[lib/Laser/findBrightestPoint.js](./lib/Laser/findBrightestPoint.js)

The brightest point is calculated using the following steps:
1. An image is loaded from the camera, and sent to the webworker.
2. 🕷️ If background subtraction is on, the background image is subtracted from the current image.
3. 🕷️ The brightest point in the image is searched for.
4. 🕷️ If background subtraction is on, a percentage of the background image is added to a percentage of the current image.
5. 🕷️ Return the brightest point value and coordinates.
6. Do it again.

# Surface

## Correspondance
A 2D mapping between camera and projector coordinates. This is calculated using Grey Code. [lib/Scan/correspondance.js](./lib/Scan/Correspondance.js)





    

