mipi - Blogs - diydrones2024-03-29T06:57:03Zhttps://diydrones.com/profiles/blogs/feed/tag/mipiCustom Raspberry Pi HQ camera gets 40x optical zoom lenshttps://diydrones.com/profiles/blogs/custom-raspberry-pi-hq-camera-gets-40x-optical-zoom-lens2022-01-24T14:13:22.000Z2022-01-24T14:13:22.000ZSaulius L.https://diydrones.com/members/SauliusL<div><img src="https://storage.ning.com/topology/rest/1.0/file/get/10038391267?profile=RESIZE_400x&width=400"></div><div><p>With the introduction of motorized zoom lenses, the next logical step was matching the sensor board. Sure there are countless suitable sensors from various manufacturers like Sony semiconductors, Onsemi, Aptina, and many more. But lack of good support from the SOC side suggested starting from IMX477. It is a reasonably modern 12M image sensor used by many single-board computers like Raspberry Pi, NVIDIA Jetson, and others.</p><a href="https://www.kurokesu.com/main/wp-content/uploads/2022/01/IMG_4770__s.jpg"><img class="wp-image-3027" src="https://www.kurokesu.com/main/wp-content/uploads/2022/01/IMG_4770__s-1024x682.jpg" alt="" width="1024" height="682" /></a><p>Raspberry Pi locks cameras with a security chip and prohibits non-authorized cameras with standard boards. Luckily this security feature is not used by compute modules. Motorized lenses have dedicated, and in most cases, unique direct mount features. So a custom camera module is a must, thus introducing the <a href="https://www.kurokesu.com/shop/IMX477_Z1_LEGACY" target="_blank">IMX477 MIPI CSI2 camera</a> board.</p><div class="wp-block-image"><a href="https://www.kurokesu.com/main/wp-content/uploads/2022/01/IMG_4757__s.jpg"><img class="wp-image-3028" src="https://www.kurokesu.com/main/wp-content/uploads/2022/01/IMG_4757__s-1024x876.jpg" alt="" width="365" height="312" /></a></div><p>This is the first of a few upcoming camera modules. Note multiple mounting features – this allows single-board use with many lenses.</p><p>Features of the lens kit:</p><ul><li>Lens optical train – 3 stepper motors for Zoom, Focus and compensate lens groups</li><li>Iris</li><li>Two optical filters: IR CUT and NIR</li><li>Reference optical train elements</li><li>Runs on <a href="https://github.com/Kurokesu/SCE2-GRBL" target="_blank">GRBL firmware</a> ported on STM32 CPU with four axis motion planner</li></ul><h2>Using the camera with Raspberry Pi compute module</h2><p>There is a <a href="https://www.raspberrypi.com/documentation/accessories/camera.html" target="_blank">great resource</a> about the IMX477 camera on Raspberry Pi pages, feel free to learn how to control and use it from Raspberry Pi. Below is a simple recipe for streaming real-time video from RPI to a computer.</p><h3>Run on computer first</h3><pre class="wp-block-code"><code>gst-launch-1.0 udpsrc port=5004 ! "application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)JPEG,a-framerate=(string)40.000000,a-framesize=(string)1280-720,payload=(int)26" ! rtpjpegdepay ! decodebin ! autovideosink</code></pre><h3>Run on RPI as a second step</h3><pre class="wp-block-code"><code># Install librariessudo apt -y install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev# Start streamerraspivid -t 0 -cd MJPEG -awb greyworld -mm average -w 2028 -h 1520 -fps 30 -b 132000000 -o - | gst-launch-1.0 fdsrc ! "image/jpeg,framerate=30/1" ! jpegparse ! rtpjpegpay ! udpsink host=<COMPUTER_IP> port=5004</code></pre><h3>Control the lens</h3><p>The SCE2-SDK control software can be forked from <a href="https://github.com/Kurokesu/SCE2-SDK" target="_blank">GitHub</a>. Python code allows code reuse on many operating systems and keeps it human-readable, thus open for customizations.</p><a href="https://www.kurokesu.com/main/wp-content/uploads/2022/01/screenshot.png"><img class="wp-image-3038" src="https://www.kurokesu.com/main/wp-content/uploads/2022/01/screenshot.png" alt="" width="952" height="780" /></a><ul><li>Download and install <a href="https://www.python.org/downloads/windows/">https://www.python.org/downloads/windows/</a> (tested with Python 3.10 on Win10 and Python 3.8.10 on Win7)<ul><li>Check <code>Add Python 3.8 to PATH</code> in the first setup window!</li><li>Restart computer</li></ul></li><li>Clone (or download zip archive) from GitHub repository: <a href="https://github.com/Kurokesu/SCE2-SDK">https://github.com/Kurokesu/SCE2-SDK</a> in preferred directory</li><li>Open console at <code>03_lens_tester_gui</code> folder</li><li>Install dependencies:</li></ul><pre class="wp-block-code"><code>pip install -r requirements.txt</code></pre><ul><li>Run demo with command</li></ul><pre class="wp-block-code"><code>python main.py</code></pre><h2>Results</h2><p>And finally, demonstration video cycling through a few presets and changing filters.</p><div class="wp-block-embed__wrapper"><span class="embed-youtube" style="text-align:center;display:block;"><iframe class="youtube-player" style="border:0;" src="https://www.youtube.com/embed/6Rh9UC2JAeg?version=3&rel=1&showsearch=0&showinfo=1&iv_load_policy=1&fs=1&hl=en-US&autohide=2&wmode=transparent" width="1140" height="642" allowfullscreen=""></iframe></span></div><h2>Links</h2><ul><li><a title="SCE2-SDK" href="https://github.com/Kurokesu/SCE2-SDK">SCE2-SDK</a> repository on GitHub</li><li>E-store <a title="camera modules" href="https://www.kurokesu.com/shop/camera_modules">camera modules</a></li><li>E-store motorized <a title="zoom lenses" href="https://www.kurokesu.com/shop/motorized_zoom_lenses">zoom lenses</a></li><li><a title="3D model repository" href="https://github.com/Kurokesu/3d_models">3D model repository</a> on GitHub</li></ul></div>