papachristou marios arxiv:1503.04315v1 [cs.oh] 14 mar 2015papachristou marios p2p lab, ioannina...
TRANSCRIPT
Designing and Building a Three-dimensional
Projective Scanner for Smartphones
Papachristou MariosP2P Lab, Ioannina & P2P Foundation
Abstract
One of the frustrating things in the digital fabrication era is that its media are neither affordablenor easily accessible and usable. Three-dimensional (3D) fabrication media (DFM) such as 3DPrinters and 3D Scanners have experienced an upsurge in popularity, while the latter remainexpensive and hard to function. With this paper, we aim to present you the RhoScanner Project - aan affordable and efficient Three-dimensional Projective Scanner for Smart-phones, hence sheddinglight on the extended capabilities of digital fabrication media on popular use.
Keywords digital fabrication, rapid prototyping, three-dimensional scanning, mobile applica-tion, algorithm optimization, Python, Cython, Android
1 Introduction
Nowadays, the need for digital fabrication (DF)devices is constantly rising. The emergence ofsuch techniques and technologies on a popu-lar basis, like three-dimensional (3D) printingand scanning has been gaining ground the re-cent years, thence it has been a common prob-lem that even if the costs of 3D Printers areconstantly reducing, the costs of 3D Scannershave not changed so radically according to [1].Thereby, an austere structure whose goal is tominimize materialization costs, empowered withthe extended capabilities of free and open-sourcesoftware targeted to mobile devices is a modelthat perfectly fits the current situation.
Having this in mind, we decided to reverse-engineer a 3D scanner and create an opensourceproject under the name RhoScanner1 whichconsists of the following tools: a) RhoScanner(The Core Scanner Application), b) RhoScanner
Viewer (A viewer for 3D files that covers themere basics of OBJ file viewing), a PCD Plotter(A simple scatter plotter for plotting point datausing Matplotlib) and a simple OBJ Viewer forviewing OBJ files.
The project was developed in Python whichis an open-source object-oriented multi-platformprogramming language, with a large number oflibraries (e.g. for numerical analysis, computervision etc.) suitable to our needs. We chose touse Python because it offered us the desirable re-sults due to its portability and elegant program-ming style, whereas the ability to improve theperformance of the algorithms is full-fledged withtools like Cython. We have also included Kivy,a cross-platform open-source library for Pythonfor multi-touch application development with aNatural User Interface (NUI).
Finally, this paper aims to provide you with abasic guidance to the project as it contains thebasic mathematical and algorithmic concepts be-
1
arX
iv:1
503.
0431
5v1
[cs
.OH
] 1
4 M
ar 2
015
hind the ensemble. the In Section 2, we presenta brief outline of the project as well as the con-struction/implementation timeline. In Section 3,we dive into the Mathematical Background anddescribe the essential transformations in theorywhich are being used to generate the pointclouds(PCDs). Section 4 is targeted to the algorith-mic implementation of the project. Besides, itexamines the optimizations being done - or thepossible ones - to the algorithm for better per-formance. We, then, depict the Hardware partsin Section 5 and present our Results in Section5. Finally, Section 7 is the place where you canfind the conclusions of the project.
2 An Outline of the Project
Description
As described in the P2P Foundation Wiki2:
“RhoScanner is a projective mobilefully-functional three-dimensionalscanner that costs only 12USD.RhoScanner is a completely reverse-engineered project being maintainedby (...) under http://rhoscanner-team.github.io. It is being developedpurely in Python and licensed underthe GNU General Public License v3.Collaboration requests are more thanwelcome.”
generically states that RhoScanner is projec-tive, since it uses a line LASER (LL) to accom-plish curve projection. The LL is targeted to thescannable object and the deformation of the pro-jected line is accurately measured (see Section3) Additionally, it is mobile; designed and builtto run on a mobile phone (an Android Smart-phone), therefore enriching the mobility of DFmedia as well as affordable, costing only 12USD.The scanner was also reverse-engineered, based
on the observation of such machines, meaningthat it might be partly a novel approach to pre-vious work on 3D Scanners, modular with bothhardware and software extended modification ca-pabilities due to the portability of Python andthe tools it uses (Python can run both on An-droid and iOS devices), while it remains purelyfree and opensource software accesible and mod-ifiable by everyone considering that it is licensedunder the GNU General Public License v3 withhaving its source code released via Github CVS.
Timeline
The project was initiated at March, 2014. At thebeginning, the core libraries were written. Theselibraries included: a) a mini computer visionlibrary able to handle basic operations on im-ages such as shifting colour modes between RGB,HSV, HLS and YIQ and thresholding and b) amodule for handling mathematical computationsas explained in Section 2. Thereafter, the core li-braries were ready and we proceeded developinga graphical user interface and the main frame,where RhoScanner would operate (see Sections4, 5).
3 Mathematical Background
Image Preparation
Any image captured by the camera is representedas an m× n matrix. Therefore, let
I =
p11 p12 · · · p1np21 p22 · · · p2n...
.... . .
...pm1 pm2 · · · pmn
be the matrix of the image and pij a random
pixel at (i, j), i ≤ m , j ≤ n. The characteris-tics of this pixel are
pij = (Rij , Gij , Bij)
2
where Rij , Gij , Bij are the values of the red,green and blue channels respectively.
Furthermore, let T (v, α) be the thresholdfunction applied on a pixel so that:
T (v, α) =
{255 , v ≥ α0 , v < α
For each image frame that is captured thealgorithm filters the red channel of the imageand applies a threshold such that the new imageIT = [pT ij ] such that
V (pT ) = T ((V (p)), α0) ∀p ∈ R(I), α0 ∈ (0, 255)
where V (p) represents the value of the pixel ofthe red channel of I (or R(I))
Curve Transformations
Behind the whole process of development andimplementation, a mathematical backgroundwas set in order to study the curves and the oper-ations needed for getting satisfying results. Westudied curve geometric transformations whichcould generate the appropriate results for obtain-ing tuples with three elements (point clouds)
The aim of three dimensional scanning is toobtain a three dimensional point cloud (PCD),namely a smooth curve that contains all the es-sential data in order to be converted to a meshthrough a triangulation. So, let
S2 =b⋃i=a
{Pi}
be the set of points obtained by the cameraafter applying the threshold function such thatS2 ⊆
⋃ni=1
⋃mj=1{pT ij}. The following image is
an actual representation of what is obtained bythe camera where the white pixels represent thered points of the point-set (Figure 1).
The first transformation is used to convert thisset to a map (curve) C2 : x → x(y) in the two-dimensional (2D) space and a point M on the
curve. As the demanded result is derived by ob-servations3 close to one another, the best way ofsmoothing the curve was to use the arithmeticmean of the x values while y is held constant.Note that the XY plane is similar to the XYplane of a normal image. Therefore, the trans-formation is the following:
T1 : S2 → C2
according to which
M(xi, yi)→M ′(
1
m
m∑j=k
xij , yi
)≡M ′(x̄i, yi)
resulting to the smoothed curve of Figure 2.
Moreover, we used a rotary transformationRot(θ) in order to convert the the 2D curveto a 3D one, according to which the pointsare being rotated by a specific angle. To dothis we introduced two vectors ~s = (s, 0) and~v =
(s − r
2 − x0, D)
= (k,D) (as seen in Fig-ure 3). Hence, the angle is obtained via the arccosine function of
cosφ =~s · ~v‖~v‖‖~s‖
implying that θ is equal to 4
θ = 90◦ − arccos
(k√
k2 +D2
)• s is the distance between the laser and the
camera (s > 0)
• D is the distance between the flat surfaceand the camera
• r is the Y range of the camera
• x0 is the minimum X coordinate
3
which means that M(x, y)Rot(θ)−−−−→
M ′(x cos θ, y sin θ)
The final transformation
T2 : C2 → C3
is the one that results in a three-dimensionalcurve. In more detail, it does the following oper-ations for every point M of the two-dimensionalmap (curve)5
M(x, y)→M ′(x′0, y,D −∆x)
where ∆x = x − x′0 and x′0 is the minimumx coordinate after Rot(θ) resulting in returningthree dimensional points P (x, y, z) which are af-terwards saved as raw data in an ASCII file.
4 Algorithm Implementationand Optimization Techniquesand Possibilities
Postulations on using cython to opti-mize the libraries
As stated in [4], Cython is an extension tothe programming language Python that al-lows for explicit type declarations as well asporting Python code to native C (or C++)code.Therefore compiled Cython Code, whichstands for the code written with Cython andcompiled with a C/C++ compiler, behaves andperforms better than Python Code by usingthe power of the pre-existing C and FORTRANcode. For example, large numerical loops finishfaster due to native type declaration. [again [4]]
It is also essential to understand that theRhoScanner application does thousands of suchcomputations when an object is being scanned.So, the need for fast computations in a relativelyshort(er) time is obvious given that few smart-phones have high computation power nowadays.
Hence, the materialization of this project us-ing the Cython language will arise a compu-tation upsurge. Our work on porting Cythoncode to compiled C code consists of a smallpython script6 that converts Cython code to Ccode and uses arm-linux-androideabi-gcc orarm-linux-gnueabi-gcc to compile the code forthe ARM architecture. Thenceforth, the sharedlibraries that were generated can then be im-ported either in an interpreted environment, likeQPython, or pre-compiled environments, builtwith python-for-android.
Developing graphical front-ends withkivy
The Graphical User Interface (GUI) of theRhoscanner Application is a button-layered in-terface developed using the Kivy Language - anXML-like language - for widget development.Also, the OBJ Viewer is also based on the KivyLanguage which is responsible for displaying thescene.
5 Hardware & Designs
We assembled a base from MDF by puttingtwo MDF plates (40 × 40cm, 40 × 45cm) un-der a right angle. Then the smart-phone-laserholder was built with LEGO and was mountedon the MDF system (Figures 4,5). The LL andsmart-phone were mounted onto the holder Ad-ditionally, a 3D model of the smart-phone-laserholder was designed and uploaded to Thingi-verse7; available for 3D printing. The tests wererun on a 1 GHz Cortex-A5, 645MB RAM smart-phone running Android 4.0.4. Optionally, anArduino/RaspberryPi could be responsible forshifting the LL.
4
6 Results and Discussion
System Operations for artifact scanning
In this part of the paper, we attempt to presentthe system operations behind scanning artifactsas well as the artifacts themselves, from a holisticperspective. First, the artifact is placed on themain frame with the LL pointing at one of itssides. Then, the scan begins in a dark room forbest results (capturing the red channels). Aftereach frame-scan, the LL is slowly shifted usingan appropriate mechanism (e.g. an Arduino witha 5V servo/stepper motor or even carefully byhand) to the next scanning position. The processis repeated until the LL points the other side ofthe object. The time depends as well heavily onthe algorithm itself and the resolution ∆θ of theshifting mechanism which is the change in theangle of the LL for every frame. Our approach,was able obtain two point clouds (the scan is re-peated twice for each side -front and rear - ofthe object) of the same object and, after a pro-cess of noise reduction and point cloud mergingwhich was done, for the time being, by hand, weare able to acquire the final result, namely thecomplete artifact (see Figure 6).
7 Conclusions and FutureWork
With this paper, we have managed to presentthe design, mathematical background and devel-opment process of a low-cost three-dimensionalscanner being developed elaborating open-sourcestandards and rapid prototyping in the processof materialization and distribution via the GNUGeneral Public License v3 License. This projecthas synopsised existing work related to three di-mensional scanners and the rapid manufactur-ing techniques in means of simplicity and giv-ing ground to Commons-based Peer Production
[2] and the Maker Movement. Our paper hasdescribed the physical structure, the algorith-mic procedure as well as postulations on us-ing software like Cython to improve performanceon Python-based applications that run on ARMdevices. Future work will include writing bet-ter performing algorithms and feature enrich-ment such as porting triangulation algorithmsto compatible out-of-the box executable code us-ing computational geometry software (Computa-tional Geometry Algorithms Library also knownas CGAL or PCL; prefferably in C/C++ code)being bridged to application via Cython/ctypes.The characterization of the performance of thescanner under various configurations will also betaken into consideration.
All in all, a modular scanner that uses com-pletely free and open source software and openhardware costing approximately 12USD thatanyone can build - preferably in a local Mak-erspace like a hackerspace where three dimen-sional printing is broadly available - enriches,undoubtedly, the Internet of Things whose aimis to support rapid manufacturing of new prod-ucts, dynamic response to product demands, andreal-time optimization of manufacturing produc-tion and supply chain networks, by networkingmachinery, sensors and control systems together,as referred in [3]. Another possible use, besidesthis, is to educate people in graphics, mathemat-ics and computer science courses.
Acknowledgements
The author would like to thank his fellows at P2PLab and P2P Foundation for their contributionsin mentoring his work and the people who con-tributed in reviewing this paper’s preprints.
5
References
[1] Straub, Jeremy, and Scott Kerlin. ”Devel-opment of a Large, Low-Cost, Instant 3DScanner.” Technologies 2.2 (2014): 76-95.
[2] Kostakis, Vasilis, and Marios Papachristou.”Commons-based peer production and dig-ital fabrication: The case of a RepRap-based, Lego-built 3D printing-milling ma-chine.” Telematics and Informatics 31.3(2014): 434-443.
[3] Schoenwaelder, J. ”Management of Net-works with Constrained Devices: UseCases draft-ersue-opsawg-coman-use-cases-00.” (2013).
[4] Behnel, Stefan, et al. ”Cython: The bestof both worlds.” Computing in Science &Engineering 13.2 (2011): 31-39.
Notes
1http://rhoscanner-team.github.io. Accessed De-cember 2014
2http://p2pfoundation.net/RhoScanner. AccessedDecember 2014
3data4φ+ θ = 90◦5C3 : z = f(x, y)6http://goo.gl/EWhxb8. The android-cythonizer
script. Accessed December 20147http://www.thingiverse.com/thing:315116.
Three-dimensional-printable case derived from Maker-Scanner. Accessed December 2014
About the author
Marios Papachristou Marios was born inAthens (GR) in 1997. He is currently a highschool student. He has been contributing inopen-source and open-hardware projects since2010, being an ardent open-source fan. He hasworked on developing digital fabrication media
as well as bioinformatics applications using com-puter vision. He published his first paper at theage of 16, while he remains active by contribut-ing to many projects.
6
Figure 1: An arbitrary initial poinset S2.
Appendix
7
Figure 2: The resulting curve x = x(y) after T1
Figure 3: The angular calculations
8
Figure 4: The frame with the LEGO-built holder mounted on it
9
Figure 5: Close-up photograph of the LEGO-built holder which is as large as a MakerScanner3D-printedframe
Figure 6: Some scanned artifact. Post-editing stage. (merging, noise reduction etc.)
10