{"id":14977894,"url":"https://github.com/henkrijneveld/microscope-picam","last_synced_at":"2025-10-28T07:30:40.206Z","repository":{"id":51234466,"uuid":"349546654","full_name":"henkrijneveld/Microscope-PiCam","owner":"henkrijneveld","description":"Use the Raspberry PI HQ Camera with a (gemmological) microscope. Fully interactive vue based. Designed by a Gemmologist :)","archived":false,"fork":false,"pushed_at":"2023-03-13T20:52:44.000Z","size":12220,"stargazers_count":12,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-01T12:44:10.130Z","etag":null,"topics":["hq-camera","microscope","php","raspberry-pi-camera","vuejs2","webbased"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/henkrijneveld.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-19T20:24:11.000Z","updated_at":"2025-01-28T22:09:17.000Z","dependencies_parsed_at":"2024-10-11T16:41:22.455Z","dependency_job_id":"c0f0559a-bf5f-402a-bef2-a1e7195966fa","html_url":"https://github.com/henkrijneveld/Microscope-PiCam","commit_stats":{"total_commits":50,"total_committers":2,"mean_commits":25.0,"dds":0.14,"last_synced_commit":"611ec45f9459c534c838fa36fb8b8a314bbb782d"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henkrijneveld%2FMicroscope-PiCam","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henkrijneveld%2FMicroscope-PiCam/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henkrijneveld%2FMicroscope-PiCam/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henkrijneveld%2FMicroscope-PiCam/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/henkrijneveld","download_url":"https://codeload.github.com/henkrijneveld/Microscope-PiCam/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238608388,"owners_count":19500371,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hq-camera","microscope","php","raspberry-pi-camera","vuejs2","webbased"],"created_at":"2024-09-24T13:56:30.260Z","updated_at":"2025-10-28T07:30:37.986Z","avatar_url":"https://github.com/henkrijneveld.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Microscope-PiCam: Use HQ Cam with microscope\n\nWebbased application for the Raspberry Pi and the 12 MP HQ camera for taking stills, especially tailored\nfor the use with a (gemmological) microscope, but it is not limited to this.\n\n![Alt](docs/connectedtomicroscope-300.jpg?raw=true )\n\n*Connection of the camera to the third tube of a microscope.*\n\nThe raspberry PI is intended to be operated in headless mode over wifi. In this way, only the usb-powercord is attached to the pi,\nwhich has almost no effect on the mechanical stability of the camera, reducing vibrations (as an ethernet cable will).\n\n## Setting up the PI \n\nThese are more or less generic instructions, they are here to have a guide at hand.\n\n- Use a raspberry Pi 3B+ (or better), with a casing\n- Install Raspberry PI OS (32bit), preferrably the light version without the desktop (\"headless mode\")\n  (https://www.raspberrypi.org/documentation/installation/installing-images/), use the legacy Debian Buster variant.\n  - NOTE: Allthough headless configuration is possible, it is my experience that the first setup should be done\n    with keyboard and monitor connected. This way errors by yourself, or by the PI, or errors in the OS are much easier to detect.\n- Enable SSH (https://www.raspberrypi.org/documentation/remote-access/ssh/), by placing an empty file \"ssh\" in the\n  boot partition of the SD card\n- Enable headless wifi (https://www.raspberrypi.org/documentation/configuration/wireless/headless.md)\n- Put SD card in PI and login to the PI (preferably with keyboard and monitor attached)\n- To enable setting a simple password, use:\n  ```\n  sudo passwd pi\n  ```\n- Use:\n  ```\n  sudo raspi-config\n  ```\n  for set-up\n- Shut the pi down:\n   ```\n   sudo shutdown now\n   ```\n   And remove the power when it is done.\n - Attach the HQ camera.\n\nAfter this start the Pi and use it in headless mode. It is sometimes a pain to find the IP of the Pi. Usually I\nwill bind the MAC adress to a fixed IP in the router, and use a symbolic name in the HOSTS file on my PC.\n\n- Enable the camera with raspi-config. \n\n- *When using raspios buster:* Test with raspistill (https://www.raspberrypi.org/documentation/usage/camera/raspicam/raspistill.md).\n  ```\n  raspistill -t 1 -o cam.jpg\n  ``` \n  If no errors are shown, and a file cam.jpg is written, all is well.\n\n- *When using raspios bullseye:* Test with libcamera-jpeg: https://www.tomshardware.com/how-to/use-raspberry-pi-camera-with-bullseye\n  ```\n  libcamera-jpeg -o test.jpg\n  ``` \n  If no errors are shown, and a file cam.jpg is written, the camera is connect.\n  \n- *Bullseye only(!):*: the old working camerastack must be activated. It will replace the non functional libcamera stack. Do the following in the /boot/config.txt: Edit /boot/config.txt, remove the line \"camera_auto_detect=1\", and add \"start_x=1\" and \"gpu_mem=128\" (for background info read: https://forums.raspberrypi.com/viewtopic.php?t=323390) Gemcam will work now, raspistill and libcamera-jpeg won't.\n\n\nInstall two necessary applications:\n- Git for installing and updating. Of course you could also download a zip, but upgrading later is \n  easier this way. And installing Git is very simple (https://linuxize.com/post/how-to-install-git-on-raspberry-pi/).\n- Install Apache and PHP (https://www.raspberrypi.org/documentation/computers/remote-access.html#setting-up-an-apache-web-server). Remove the \nindex.html file as instructed:\n  ```\n  sudo rm /var/www/html/index.html\n  ```  \n  If there were no errors during installation, you can skip\n  the part where a test version of the index.php is made.\nIf you want to use virtual hosts, consult the documentation on raspberry.org.\n- Fire a webbrowser on a remote system, and enter the IP (or your name from the hosts file) in the\naddress bar like http://\\\u003cip number\\\u003e A Page with \"Index of\" must be shown now.\n\n## Installation Microscope-PiCam\n\nClone this repository inside the webroot (normally /var/www/html). \nIn the webroot on the pi enter (note: instead of the directory name \"gemcam\" you can choose any name you wish. In the remainer of\nthis document, I assume you choose gemcam):\n```\ncd /var/www/html\nsudo git clone https://github.com/henkrijneveld/Microscope-PiCam.git gemcam\n```\nGo to the install directory and execute the install script\n```\ncd gemcam\ncd install\nsudo ./install.sh\n```\nIf it is the first time gemcam is installed, reboot:\n```\nsudo shutdown -r now\n```\nGo to your browser:\n```\nhttp://\u003cip or name of connected pi\u003e/gemcam\n```\nThen click the Start Camera button. A picture should be visible (if camera attached and enough light).\nSometimes the camera needs some time and won't adjust to the lighting. Push ctrl+F5 to reload the page\nand restart the camera.\n\nIf the white balance won't work, switch to auto and manual and back. The Camera\nis very picky on the sequence in which commands are sent.\n\nErrors? open the console log in your browser (F12 key)\n\nUser configuration can be done in config/config.overrides.js and config/raspigemcam.overrides.cfg\n\n\n## Upgrading\nGo to the installation directory from the webroot, do a git pull, and run install again. Example:\n```\ncd /var/www/html/gemcam\nsudo git pull\ncd install\nsudo ./install.sh\n```\nIf this leads to an unstable system, remove the gemcam directory entirely and re-install. In this \nsituation, make sure all files are deleted.\n\n## Main functional requirements of this application\n\n- The User Interface runs in a webbrowser, open it on a different system. \n\n- When using a microscope with standard foto software, I ran into the inconvenience that it \n  was necessary during the work to note seperately the subject, the magnification and \n  other parameters. Later on I had to change the filename, leading\nto mistakes and a very cumbursome process. Microscope-PiCam let you specify the filename with alle relevant information. This results\nin meaningfull filenames like: garnet-1.5x-0.5R-inclusion-20210321-210304.jpg. Files are downloaded to your system,\nand stored in a mediafolder on the Pi itself. Maybe it seems strange at first, ben when you start copying files it is \na very convenient way to not get confused.\n- The second problem using a camera with a microscope is focussing. A (gemmological) stereo \n  microscope has objectives somewhat tilted from the horizontal plane to achieve the 3D \n  effect. In Microscope-PiCam, you see a preview (in reduced resolution: 1024px. Full picture\nresolution will be 4056px). However, with a 4x or 8x magnification it is possible to get good focussing.\n- The whitebalance is an other issue. Through the microscope you can seldom use the balancing out of the box. Microscope-PiCam\nlet you manually select the gains in red and blue (green stays constant as part of the design of the HQ camera).\nBy carefully obsering the image, comparing it to the image in the microscope (\"eye-balling\") it can be fine tuned to achieve the \nright colors. Note that white balancing is processed on the camera, so 10 or 12 bits are used (raw processing).\nAn additional grey card (with white, 18% grey, and black) can be helpfull.\n\n## Usage\n\nJust play with the software!\n\nKeep an eye on the histogram, it should not clip, and use the whole range for the totals. If you want to find the \ncorrect whitebalance, the color tab is very handy with a gray card.\n\nStart out with exposure set to auto, and switch to off if it settled. You can now change the external \nlightning or the exposure compensation. The other controls can be set to get the most detail and dynamic range.\nLook at the live histogram to avoid clipping.\nSometimes the camera will need less light then the eye, so also play with the brightness controls on your microscope. \n\nIf you want to make a stack, switch to stackmode and rest the counter. Make consecutive pictures and use\nstacking software. I do not use a gemmological microscope when stacking, but a 300x objective on a column stand.\n\nAfter initial load, the camera must be started with the button \"start camera\". Sometimes you have to restart twice.\n\nWhen done, shutdown the PI with the button in the upper bar. Wait a while before removing power.\n\nNote that the primary driver for the quality of the picture is the reduction lens between microscope and camera. \n\n![Alt](docs/screenshot-emerald.jpg?raw=true )\n\n*In use with a synthetic hydrothermal emerald.*\n\n## Development\n\nThe software was developed with phpstorm, and the pi was connected as a remote server.\n\nThe UI can be developed (for a part) with no Pi connected. Go to the docker subdirectory and start:\n```\ncd /var/www/html/gemcam/docker\n# start docker\n./start.sh\n\n# refresh docker after changes to the docker files itself\n./refresh.sh\n\n# enter the docker image\n./gotowebserver.sh\n\n# stop and remove all containers on your PC \n./stopandremove.sh\n```\n\nYou can use the testsystem on localhost. When the software detects that localhost is used, it will show two\nimages as testimage. Note, that the camerasettings can be adapted, but will have no effect (the settings are processed\nin the camera module itself, so when it is not attached, nothing will happen to the picture).\n\n## Security\n\nNone, anybody on the same (w)lan can access the camera.\n\nThe application is meant to be connected to a PC in the direct vicinity of the microscope/camera. All security\nmust be implemented by using a dedicated wifi wlan. For technical reasons, the apache user (www-data) runs with\nfull sudo rights, no password necessary. Making this secure would require a lot of extra effort with no pay-off\nin this use case. Highly recommended to make this application not available on a broader network.\n\n![Alt](docs/bumblbee-fov3mm.jpg?raw=true )\n\n*Air bubbles in resin filled cavity of a bumlbee jasper (horizontal field of view 3mm).*\n\n\n## Known issues and limitations\n\n- The exposure settings do seem to be somewhat unstable. I am not sure if this is in the PI or the\n  driver. It can sometimes lead to a crash of apache. The only way to solve this is to ssh into the PI, \n  go to the gemcam subdir. Run \"sudo ./stop.sh\" and restart apache: \"sudo service apache2 restart\". I am currently\n  investigating this.\n- It is tested only on my own systems: 2 Raspberry 3B+ with a camera connected. I expect some difficulties for\n  first time users.\n- This is my first Vue application. There are still some quirks in the event handling. It runs with vue.js in\n  development mode.\n- Error messages on the UI itself are almost absent. When an error occurs, it is best to go to the development tools\n    in the browser (F12 key), and inspect the log in the console.\n- The ISO is fixed on 100. You can never be sure with the camera drivers, but the lower the ISO, the sharper the image. \nIt may result in longer exposure times.\n\n# Acknowledgements\n\nThe mediabrowser is the \"Tiny File Manager\" script (https://tinyfilemanager.github.io), renamed to index.php\nin php/filemanager. The config.php used with this filemanager is adapted to automatically set the media directory \nto the media subdirectory under the site root.\n\nThe gemcamdriver is from https://github.com/henkrijneveld/userland, subdir raspigemcam-bin. It is a\nnon-backwards compatible adapted copy from raspimjpeg. For more information, see the readme\naccompanying the aforementioned repository.\n\nThe vue script is from vuejs.org\n\nThe general idea of Microscope-PiCam is based on RPi_Cam_Web_Interface (https://github.com/silvanmelchior/RPi_Cam_Web_Interface).\nThis is a very generic application with a lot of functionality of no use for still fotography. I considered the userinterface\nsuboptimal for my goals. Unfortunately, the UI was based on plain javascript and ajax. Vue seems a better choice nowadays.\nThe wiki of this project can be of use: https://elinux.org/RPi-Cam-Web-Interface\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenkrijneveld%2Fmicroscope-picam","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhenkrijneveld%2Fmicroscope-picam","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenkrijneveld%2Fmicroscope-picam/lists"}