BitmapToolkit Scol plugin
ArToolkit.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25/*
26 Toolkit based on OpenCV library
27 First version : dec 2010
28 Author : Bastien BOURINEAU
29 */
30
31#include "ArCameraParam.h"
32#include "ArManager.h"
33#include "ArMarker.h"
34#include "ScolConvert.h"
35
36 // Scol obj
40
41// CALLBACK
42int NBMARKERCB = 1;
44int NBBLOBCB = 0;
45
48
55 /*******************************************
56 * CAMERA PARAM
57 ********************************************/
58int destroyArCameraParamObj(mmachine m, SCOL_PTR_TYPE handsys, int obj)
59{
60 ArCameraParam* arCameraParamOBJ = MMgetPointer<ArCameraParam*>(m, MTOP(obj));
61 SAFE_DELETE(arCameraParamOBJ);
62
63 MMsetPointer<ArCameraParam*>(m, MTOP(obj), 0);
64
65 MMechostr(MSKDEBUG, "ArCameraParam destroyed.\n");
66 return 0;
67}
68
69
83int _CRarCameraParam(mmachine m)
84{
85#ifdef _SCOL_DEBUG_
86 MMechostr(MSKDEBUG, "_CRarCameraParam\n");
87#endif
88
89 int ifile = MMpull(m);
90 int ffarclip = MMpull(m);
91 int fnearclip = MMpull(m);
92 int sheight = MMpull(m);
93 int swidth = MMpull(m);
94
95 if ((swidth == NIL) || (sheight == NIL))
96 {
97 MMset(m, 0, NIL);
98 return 0;
99 }
100
101 int width = 1;
102 int height = 1;
103
104 if (MTOI(swidth) > 1)
105 width = MTOI(swidth);
106 if (MTOI(sheight) > 1)
107 height = MTOI(sheight);
108
109 float nearclip = 0.01;
110 if (fnearclip != NIL)
111 nearclip = MTOF(fnearclip);
112
113 float farclip = 10000.0;
114 if (ffarclip != NIL)
115 farclip = MTOF(ffarclip);
116
117 std::string yamlfile("");
118 if (ifile != NIL)
119 yamlfile = MMstartstr(m, MTOP(ifile));
120
121 ArCameraParam* ArCameraParamOBJ = new ArCameraParam(width, height, nearclip, farclip, yamlfile);
122
123 if (!ArCameraParamOBJ)
124 {
125 MMechostr(MSKDEBUG, "Failed to create camera param\n");
126 MMset(m, 0, NIL);
127 return 0;
128 }
129
130 if (MMpushPointer(m, ArCameraParamOBJ) != 0)
131 {
132 SAFE_DELETE(ArCameraParamOBJ);
133 MMset(m, 0, NIL);
134 return MERRMEM;
135 }
136
137#ifdef _SCOL_DEBUG_
138 MMechostr(MSKDEBUG, "ok\n");
139#endif
140 return OBJcreate(m, OBJCAMERAPARAMSCOL, SCOL_PTR ArCameraParamOBJ, NIL, 0);
141}
142
143
159{
160#ifdef _SCOL_DEBUG_
161 MMechostr(MSKDEBUG, "_CRarCameraParamIntrinsics\n");
162#endif
163
164 int icenter = MMpull(m);
165 int ifocal = MMpull(m);
166 int ffarclip = MMpull(m);
167 int fnearclip = MMpull(m);
168 int sheight = MMpull(m);
169 int swidth = MMpull(m);
170
171 if ((swidth == NIL) || (sheight == NIL))
172 {
173 MMset(m, 0, NIL);
174 return 0;
175 }
176
177 int width = 1;
178 int height = 1;
179
180 if (MTOI(swidth) > 1)
181 width = MTOI(swidth);
182 if (MTOI(sheight) > 1)
183 height = MTOI(sheight);
184
185 float nearclip = 0.01;
186 if (fnearclip != NIL)
187 nearclip = MTOF(fnearclip);
188
189 float farclip = 10000.0;
190 if (ffarclip != NIL)
191 farclip = MTOF(ffarclip);
192
193 float f = std::max(width, height);
194 Vector2 focal(f, f);
195 int tfocal = MTOP(ifocal);
196
197 if (tfocal != NIL)
198 {
199 int fx = MMfetch(m, tfocal, 0);
200 int fy = MMfetch(m, tfocal, 1);
201 if ((fx != NIL) && (fy != NIL))
202 focal = Vector2(MTOF(fx), MTOF(fy));
203 }
204
205 Vector2 center(static_cast<float>(width) * 0.5f, static_cast<float>(height) * 0.5f);
206 int tcenter = MTOP(icenter);
207 if (tcenter != NIL)
208 {
209 int cx = MMfetch(m, tcenter, 0);
210 int cy = MMfetch(m, tcenter, 1);
211
212 if ((cx != NIL) && (cy != NIL))
213 center = Vector2(MTOF(cx), MTOF(cy));
214 }
215
216 ArCameraParam* ArCameraParamOBJ = new ArCameraParam(width, height, nearclip, farclip, focal, center);
217
218 if (!ArCameraParamOBJ)
219 {
220 MMechostr(MSKDEBUG, "Failed to create camera param\n");
221 MMset(m, 0, NIL);
222 return 0;
223 }
224
225 if (MMpushPointer(m, ArCameraParamOBJ) != 0)
226 {
227 SAFE_DELETE(ArCameraParamOBJ);
228 MMset(m, 0, NIL);
229 return MERRMEM;
230 }
231
232#ifdef _SCOL_DEBUG_
233 MMechostr(MSKDEBUG, "ok\n");
234#endif
235 return OBJcreate(m, OBJCAMERAPARAMSCOL, SCOL_PTR ArCameraParamOBJ, NIL, 0);
236}
237
238
247int _DSarCameraParam(mmachine m)
248{
249#ifdef _SCOL_DEBUG_
250 MMechostr(MSKDEBUG, "_DSarCameraParam\n");
251#endif
252
253 int obj = MMget(m, 0);
254 if (obj == NIL)
255 {
256 MMset(m, 0, NIL);
257 return 0;
258 }
259
260 OBJdelTM(m, OBJCAMERAPARAMSCOL, obj);
261
262 MMset(m, 0, ITOM(0));
263
264#ifdef _SCOL_DEBUG_
265 MMechostr(MSKDEBUG, "ok\n");
266#endif
267 return 0;
268}
269
279{
280#ifdef _SCOL_DEBUG_
281 MMechostr(MSKDEBUG, "_SETcameraSensorsQuat\n");
282#endif
283
284 int iquat = MMpull(m);
285 int obj = MMget(m, 0);
286 if ((obj == NIL) || (iquat == NIL))
287 {
288 MMset(m, 0, NIL);
289 return 0;
290 }
291
292 ArCameraParam* cameraParamOBJ = MMgetPointer<ArCameraParam*>(m, MTOP(obj));
293 if (cameraParamOBJ == NULL)
294 {
295 MMset(m, 0, NIL);
296 return 0;
297 }
298
299 int q1 = MTOP(iquat);
300 int x1 = MMfetch(m, q1, 0);
301 int y1 = MMfetch(m, q1, 1);
302 int z1 = MMfetch(m, q1, 2);
303 int w1 = MMfetch(m, q1, 3);
304
305 if ((x1 == NIL) || (y1 == NIL) || (z1 == NIL) || (w1 == NIL))
306 {
307 MMset(m, 0, NIL);
308 return 0;
309 }
310
311 cameraParamOBJ->SetCameraQuat(BtQuaternion(MTOF(w1), MTOF(x1), MTOF(y1), MTOF(z1)));
312
313#ifdef _SCOL_DEBUG_
314 MMechostr(MSKDEBUG, "ok\n");
315#endif
316 return 0;
317}
318
329{
330#ifdef _SCOL_DEBUG_
331 MMechostr(MSKDEBUG, "_GETarProjectionMatrix\n");
332#endif
333
334 int iheight = MMpull(m);
335 int iwidth = MMpull(m);
336 int obj = MMget(m, 0);
337 if ((obj == NIL) || (iheight == NIL) || (iwidth == NIL))
338 {
339 MMset(m, 0, NIL);
340 return 0;
341 }
342
343 ArCameraParam* cameraParamOBJ = MMgetPointer<ArCameraParam*>(m, MTOP(obj));
344 if (cameraParamOBJ == NULL)
345 {
346 MMset(m, 0, NIL);
347 return 0;
348 }
349
350 double proj_mat[16];
351 cameraParamOBJ->GetProjectionMatrix(proj_mat, cv::Size(MTOI(iwidth), MTOI(iheight)));
352
353 int tupleMat = MMmalloc(m, 4, TYPETAB);
354 if (tupleMat == NIL)
355 {
356 MMset(m, 0, NIL);
357 return MERRMEM;
358 }
359
360 int tupleMat0 = MMmalloc(m, 4, TYPETAB);
361 int tupleMat1 = MMmalloc(m, 4, TYPETAB);
362 int tupleMat2 = MMmalloc(m, 4, TYPETAB);
363 int tupleMat3 = MMmalloc(m, 4, TYPETAB);
364
365 if ((tupleMat0 == NIL) || (tupleMat1 == NIL) || (tupleMat2 == NIL) || (tupleMat3 == NIL))
366 {
367 MMset(m, 0, NIL);
368 return MERRMEM;
369 }
370
371 MMstore(m, tupleMat0, 0, FTOM(static_cast<float>(proj_mat[0])));
372 MMstore(m, tupleMat0, 1, FTOM(static_cast<float>(proj_mat[4])));
373 MMstore(m, tupleMat0, 2, FTOM(static_cast<float>(proj_mat[8])));
374 MMstore(m, tupleMat0, 3, FTOM(static_cast<float>(proj_mat[12])));
375
376 MMstore(m, tupleMat1, 0, FTOM(static_cast<float>(proj_mat[1])));
377 MMstore(m, tupleMat1, 1, FTOM(static_cast<float>(proj_mat[5])));
378 MMstore(m, tupleMat1, 2, FTOM(static_cast<float>(proj_mat[9])));
379 MMstore(m, tupleMat1, 3, FTOM(static_cast<float>(proj_mat[13])));
380
381 MMstore(m, tupleMat2, 0, FTOM(static_cast<float>(proj_mat[2])));
382 MMstore(m, tupleMat2, 1, FTOM(static_cast<float>(proj_mat[6])));
383 MMstore(m, tupleMat2, 2, FTOM(static_cast<float>(proj_mat[10])));
384 MMstore(m, tupleMat2, 3, FTOM(static_cast<float>(proj_mat[14])));
385
386 MMstore(m, tupleMat3, 0, FTOM(static_cast<float>(proj_mat[3])));
387 MMstore(m, tupleMat3, 1, FTOM(static_cast<float>(proj_mat[7])));
388 MMstore(m, tupleMat3, 2, FTOM(static_cast<float>(proj_mat[11])));
389 MMstore(m, tupleMat3, 3, FTOM(static_cast<float>(proj_mat[15])));
390
391 MMstore(m, tupleMat, 0, PTOM(tupleMat0));
392 MMstore(m, tupleMat, 1, PTOM(tupleMat1));
393 MMstore(m, tupleMat, 2, PTOM(tupleMat2));
394 MMstore(m, tupleMat, 3, PTOM(tupleMat3));
395
396 MMset(m, 0, PTOM(tupleMat));
397
398#ifdef _SCOL_DEBUG_
399 MMechostr(MSKDEBUG, "ok\n");
400#endif
401 return 0;
402}
403
404
413int _SETcameraOffset(mmachine m)
414{
415#ifdef _SCOL_DEBUG_
416 MMechostr(MSKDEBUG, "_SETcameraOffset\n");
417#endif
418
419 int ivec = MMpull(m);
420 int obj = MMget(m, 0);
421 if ((obj == NIL) || (ivec == NIL))
422 {
423 MMset(m, 0, NIL);
424 return 0;
425 }
426
427 ArCameraParam* cameraParamOBJ = MMgetPointer<ArCameraParam*>(m, MTOP(obj));
428 if (cameraParamOBJ == NULL)
429 {
430 MMset(m, 0, NIL);
431 return 0;
432 }
433
434 int vec = MTOP(ivec);
435 int x = MMfetch(m, vec, 0);
436 int y = MMfetch(m, vec, 1);
437 int z = MMfetch(m, vec, 2);
438
439 if ((x == NIL) || (y == NIL) || (z == NIL))
440 {
441 MMset(m, 0, NIL);
442 return 0;
443 }
444
445 cameraParamOBJ->SetCameraOffset(Vector3(MTOF(x), MTOF(y), MTOF(z)));
446
447#ifdef _SCOL_DEBUG_
448 MMechostr(MSKDEBUG, "ok\n");
449#endif
450 return 0;
451}
452
453
461int _GETcameraOffset(mmachine m)
462{
463#ifdef _SCOL_DEBUG_
464 MMechostr(MSKDEBUG, "_GETcameraOffset\n");
465#endif
466
467 int obj = MMget(m, 0);
468 if (obj == NIL)
469 {
470 MMset(m, 0, NIL);
471 return 0;
472 }
473
474 ArCameraParam* cameraParamOBJ = MMgetPointer<ArCameraParam*>(m, MTOP(obj));
475 if (cameraParamOBJ == NULL)
476 {
477 MMset(m, 0, NIL);
478 return 0;
479 }
480
481 Vector3 offset = cameraParamOBJ->GetCameraOffset();
482
483 int tuple = MMmalloc(m, 3, TYPETAB);
484 if (tuple == NIL)
485 {
486 MMpush(m, NIL);
487 return MERRMEM;
488 }
489
490 MMstore(m, tuple, 0, FTOM(offset.x));
491 MMstore(m, tuple, 1, FTOM(offset.y));
492 MMstore(m, tuple, 2, FTOM(offset.z));
493 MMset(m, 0, PTOM(tuple));
494
495#ifdef _SCOL_DEBUG_
496 MMechostr(MSKDEBUG, "ok\n");
497#endif
498 return 0;
499}
500
501
502/*******************************************
503* Blob detector
504********************************************/
505
506int destroyBlobObj(mmachine m, SCOL_PTR_TYPE handsys, int obj)
507{
508
509 ArBlobDetector* blobDetector = MMgetPointer<ArBlobDetector*>(m, MTOP(obj));
511
512 MMsetPointer<ArBlobDetector*>(m, MTOP(obj), 0);
513
514 MMechostr(MSKDEBUG, "BlobDetector destroyed.\n");
515 return 0;
516}
517
526int _DSblobDetector(mmachine m)
527{
528#ifdef _SCOL_DEBUG_
529 MMechostr(MSKDEBUG, "_DSblobDetector\n");
530#endif
531
532 int obj = MMget(m, 0);
533 if (obj == NIL)
534 {
535 MMset(m, 0, NIL);
536 return 0;
537 }
538
539 OBJdelTM(m, OBJBLOBSCOL, obj);
540
541 MMset(m, 0, ITOM(0));
542
543#ifdef _SCOL_DEBUG_
544 MMechostr(MSKDEBUG, "ok\n");
545#endif
546 return 0;
547}
548
576int _CRblobDetector(mmachine m)
577{
578#ifdef _SCOL_DEBUG_
579 MMechostr(MSKDEBUG, "_CRblobDetector\n");
580#endif
581
582 int iInertia = MMpull(m);
583 bool filterInertia = false;
584 float minIntertia = 0.1f;
585 float maxIntertia = 1.0f;
586
587 if (iInertia != NIL)
588 {
589 int iFilterInertia = MMfetch(m, MTOP(iInertia), 0);
590 if (iFilterInertia != NIL)
591 filterInertia = (MTOI(iFilterInertia) > 0) ? true : false;
592
593 int iMinInertia = MMfetch(m, MTOP(iInertia), 1);
594 if (iMinInertia != NIL)
595 minIntertia = abs(MTOF(iMinInertia));
596
597 int iMaxInertia = MMfetch(m, MTOP(iInertia), 2);
598 if (iMaxInertia != NIL)
599 maxIntertia = abs(MTOF(iMaxInertia));
600 }
601
602 int iConvexcity = MMpull(m);
603 bool filterConvexcity = false;
604 float minConvexcity = 0.95f;
605 float maxConvexcity = 1.0f;
606
607 if (iConvexcity != NIL)
608 {
609 int iFilterConvexcity = MMfetch(m, MTOP(iConvexcity), 0);
610 if (iFilterConvexcity != NIL)
611 filterConvexcity = (MTOI(iFilterConvexcity) > 0) ? true : false;
612
613 int iMinConvexcity = MMfetch(m, MTOP(iConvexcity), 1);
614 if (iMinConvexcity != NIL)
615 minConvexcity = abs(MTOF(iMinConvexcity));
616
617 int iMaxConvexcity = MMfetch(m, MTOP(iConvexcity), 2);
618 if (iMaxConvexcity != NIL)
619 maxConvexcity = abs(MTOF(iMaxConvexcity));
620 }
621
622 int iColor = MMpull(m);
623 bool filterColor = false;
624 int color = 0;
625
626 if (iColor != NIL)
627 {
628 int iFilterColor = MMfetch(m, MTOP(iColor), 0);
629 if (iFilterColor != NIL)
630 filterColor = (MTOI(iFilterColor) > 0) ? true : false;
631
632 int iDetectColor = MMfetch(m, MTOP(iColor), 1);
633 if (iDetectColor != NIL)
634 color = abs(MTOI(iDetectColor));
635 }
636
637 int iCircularity = MMpull(m);
638 bool filterCircularity = false;
639 float minCircularity = 0.8f;
640 float maxCircularity = 1.0f;
641
642 if (iCircularity != NIL)
643 {
644 int iFilterCircularity = MMfetch(m, MTOP(iCircularity), 0);
645 if (iFilterCircularity != NIL)
646 filterCircularity = (MTOI(iFilterCircularity) > 0) ? true : false;
647
648 int iMinCircularity = MMfetch(m, MTOP(iCircularity), 1);
649 if (iMinCircularity != NIL)
650 minCircularity = abs(MTOF(iMinCircularity));
651
652 int iMaxCircularity = MMfetch(m, MTOP(iCircularity), 2);
653 if (iMaxCircularity != NIL)
654 maxCircularity = abs(MTOF(iMaxCircularity));
655 }
656
657 int iArea = MMpull(m);
658 bool filterArea = false;
659 int minArea = 25;
660 int maxArea = 5000;
661
662 if (iArea != NIL)
663 {
664 int iFilterArea = MMfetch(m, MTOP(iArea), 0);
665 if (iFilterArea != NIL)
666 filterArea = (MTOI(iFilterArea) > 0) ? true : false;
667
668 int iMinArea = MMfetch(m, MTOP(iArea), 1);
669 if (iMinArea != NIL)
670 minArea = abs(MTOI(iMinArea));
671
672 int iMaxArea = MMfetch(m, MTOP(iArea), 2);
673 if (iMaxArea != NIL)
674 maxArea = abs(MTOI(iMaxArea));
675 }
676
677 int iThreshold = MMpull(m);
678 int minThreshold = 50;
679 int maxThreshold = 220;
680 int thStep = 10;
681
682 if (iThreshold != NIL)
683 {
684 int iStepThreshold = MMfetch(m, MTOP(iThreshold), 1);
685 if (iStepThreshold != NIL)
686 thStep = std::max(1, abs(MTOI(iStepThreshold)));
687
688 int iMinThreshold = MMfetch(m, MTOP(iThreshold), 1);
689 if (iMinThreshold != NIL)
690 minThreshold = abs(MTOI(iMinThreshold));
691
692 int iMaxThreshold = MMfetch(m, MTOP(iThreshold), 2);
693 if (iMaxThreshold != NIL)
694 maxThreshold = abs(MTOI(iMaxThreshold));
695 }
696
697 int iMinRepeat = MMpull(m);
698 int minRepeat = 1;
699
700 if (minRepeat != NIL)
701 minRepeat = std::max(1, abs(MTOI(minRepeat)));
702
703 int iMinDist = MMpull(m);
704 int minDist = 10;
705
706 if (iMinDist != NIL)
707 minDist = abs(MTOI(iMinDist));
708
709 cv::SimpleBlobDetector::Params params;
710 params.filterByArea = filterArea;
711 params.minArea = (float)minArea;
712 params.maxArea = (float)maxArea;
713
714 params.filterByCircularity = filterCircularity;
715 params.minCircularity = minCircularity;
716 params.maxCircularity = maxCircularity;
717
718 params.filterByColor = filterColor;
719 params.blobColor = color;
720
721 params.filterByConvexity = filterConvexcity;
722 params.minConvexity = minConvexcity;
723 params.maxConvexity = maxConvexcity;
724
725 params.filterByInertia = filterInertia;
726 params.minInertiaRatio = minIntertia;
727 params.maxInertiaRatio = maxIntertia;
728
729 params.minThreshold = (float)minThreshold;
730 params.maxThreshold = (float)maxThreshold;
731
732 params.minDistBetweenBlobs = (float)minDist;
733 params.minRepeatability = minRepeat;
734 params.thresholdStep = (float)thStep;
735
736 ArBlobDetector* blobDetector = ArManager::GetInstance()->AddBlobDetector(params);
737
738 if (!blobDetector)
739 {
740 MMechostr(MSKDEBUG, "Failed to create blob detector\n");
741 MMset(m, 0, NIL);
742 return 0;
743 }
744
745 if ((MMpushPointer(m, blobDetector) != 0))
746 {
748 MMset(m, 0, NIL);
749 return MERRMEM;
750 }
751
752#ifdef _SCOL_DEBUG_
753 MMechostr(MSKDEBUG, "ok\n");
754#endif
755 return OBJcreate(m, OBJBLOBSCOL, SCOL_PTR blobDetector, NIL, 0);
756}
757
758
767int _GETdetectedBlobs(mmachine m)
768{
769#ifdef _SCOL_DEBUG_
770 MMechostr(MSKDEBUG, "_GETdetectedBlobs\n");
771#endif
772
773 int blobTab = MMpull(m);
774 if (blobTab == NIL)
775 {
776 MMpush(m, NIL);
777 return 0;
778 }
779
780 ArBlobDetector* blobDetector = MMgetPointer<ArBlobDetector*>(m, MTOP(blobTab));
781 if (blobDetector == 0)
782 {
783 MMpush(m, NIL);
784 return 0;
785 }
786
787 std::vector<cv::Point3f> ldots = blobDetector->GetLastDotList();
788 for (unsigned int i = 0; i < ldots.size(); i++)
789 {
790 cv::Point3f data = ldots.at(i);
791
792 int ptuple = MMmalloc(m, 3, TYPETAB);
793 if (ptuple == NIL)
794 {
795 return MERRMEM;
796 }
797 MMstore(m, ptuple, 0, ITOM((int)data.x));
798 MMstore(m, ptuple, 1, ITOM((int)data.y));
799 MMstore(m, ptuple, 2, FTOM(data.z));
800
801 MMpush(m, PTOM(ptuple));
802 }
803
804 if (MMpush(m, NIL))
805 return MERRMEM;
806
807 for (unsigned int i = 0; i < ldots.size(); i++)
808 {
809 if (MMpush(m, 2 * 2))
810 return MERRMEM;
811
812 if (int k = MBdeftab(m))
813 return k;
814 }
815
816#ifdef _SCOL_DEBUG_
817 MMechostr(MSKDEBUG, "ok\n");
818#endif
819
820 return 0;
821}
822
831int _GETblobDetectorSize(mmachine m)
832{
833#ifdef _SCOL_DEBUG_
834 MMechostr(MSKDEBUG, "_GETblobDetectorSize\n");
835#endif
836
837 int blobTab = MMpull(m);
838 if (blobTab == NIL)
839 {
840 MMpush(m, NIL);
841 return 0;
842 }
843
844 ArBlobDetector* blobDetector = MMgetPointer<ArBlobDetector*>(m, MTOP(blobTab));
845 if (blobDetector == 0)
846 {
847 MMpush(m, NIL);
848 return 0;
849 }
850
851 cv::Size size = blobDetector->GetLastBufferSize();
852
853 int ptuple = MMmalloc(m, 2, TYPETAB);
854 if (ptuple == NIL)
855 {
856 return MERRMEM;
857 }
858 MMstore(m, ptuple, 0, ITOM(size.width));
859 MMstore(m, ptuple, 1, ITOM(size.height));
860
861 MMpush(m, PTOM(ptuple));
862
863#ifdef _SCOL_DEBUG_
864 MMechostr(MSKDEBUG, "ok\n");
865#endif
866
867 return 0;
868}
869
870
871/*******************************************
872* SLAM
873********************************************/
874
884int _AddcameraSensorsImu(mmachine m)
885{
886#ifdef _SCOL_DEBUG_
887 MMechostr(MSKDEBUG, "_AddcameraSensorsImu\n");
888#endif
889
890 int idelta = MMpull(m);
891 int iaccel = MMpull(m);
892 int igyro = MMpull(m);
893 int obj = MMget(m, 0);
894
895 if ((obj == NIL) || (iaccel == NIL) || (igyro == NIL))
896 {
897 MMset(m, 0, NIL);
898 return 0;
899 }
900
901 ArCameraParam* cameraParamOBJ = MMgetPointer<ArCameraParam*>(m, MTOP(obj));
902 if (cameraParamOBJ == NULL)
903 {
904 MMset(m, 0, NIL);
905 return 0;
906 }
907
908 float delta = MTOF(idelta);
909
910 int g = MTOP(igyro);
911 int gx = MMfetch(m, g, 0);
912 int gy = MMfetch(m, g, 1);
913 int gz = MMfetch(m, g, 2);
914
915 if ((gx == NIL) || (gy == NIL) || (gz == NIL))
916 {
917 MMset(m, 0, NIL);
918 return 0;
919 }
920
921 int a = MTOP(iaccel);
922 int ax = MMfetch(m, a, 0);
923 int ay = MMfetch(m, a, 1);
924 int az = MMfetch(m, a, 2);
925
926 if ((ax == NIL) || (ay == NIL) || (az == NIL))
927 {
928 MMset(m, 0, NIL);
929 return 0;
930 }
931
932 cameraParamOBJ->AddCameraImu(Vector3(MTOF(gx), MTOF(gy), MTOF(gz)), Vector3(MTOF(ax), MTOF(ay), MTOF(az)), delta);
933
934 MMset(m, 0, ITOM(0));
935#ifdef _SCOL_DEBUG_
936 MMechostr(MSKDEBUG, "ok\n");
937#endif
938 return 0;
939}
940
941#ifdef HAVE_BTSLAM
950int _SetSlamDetectorState(mmachine m)
951{
952#ifdef _SCOL_DEBUG_
953 MMechostr(MSKDEBUG, "_SetSlamDetectorState\n");
954#endif
955
956 int state = MTOI(MMget(m, 0));
957
958 ArManager::GetInstance()->EnableSlamDetector((state) ? true : false);
959
960 MMset(m, 0, ITOM(0));
961 return 0;
962}
963
975int _SetSlamDetectorParams(mmachine m)
976{
977#ifdef _SCOL_DEBUG_
978 MMechostr(MSKDEBUG, "_SetSlamDetectorParams\n");
979#endif
980
981 int maxf = MTOI(MMpull(m));
982 int minf = MTOI(MMpull(m));
983 int nbimp = MTOI(MMpull(m));
984 int nbp = MTOI(MMget(m, 0));
985
986 if (maxf == NIL)
987 maxf = 4;
988 if (minf == NIL)
989 minf = 2;
990 if (nbimp == NIL)
991 nbimp = 500;
992 if (nbp == NIL)
993 nbp = 650;
994
995 ArManager::GetInstance()->SetSlamDetectorParams(nbp, nbimp, minf, maxf);
996
997 MMset(m, 0, ITOM(0));
998 return 0;
999}
1000
1008int _GetSlamCameraPosition(mmachine m)
1009{
1010#ifdef _SCOL_DEBUG_
1011 MMechostr(MSKDEBUG, "_GetSlamCameraPosition\n");
1012#endif
1013
1014 Vector3 pos = ArManager::GetInstance()->GetSlamCameraPostition();
1015
1016 int tuplePos = MMmalloc(m, 3, TYPETAB);
1017 if (tuplePos == NIL)
1018 {
1019 MMpush(m, NIL);
1020 return 0;
1021 }
1022
1023 MMstore(m, tuplePos, 0, FTOM(pos.x));
1024 MMstore(m, tuplePos, 1, FTOM(pos.y));
1025 MMstore(m, tuplePos, 2, FTOM(pos.z));
1026 MMpush(m, PTOM(tuplePos));
1027 return 0;
1028}
1029
1037int _GetSlamCameraOrientation(mmachine m)
1038{
1039#ifdef _SCOL_DEBUG_
1040 MMechostr(MSKDEBUG, "_GetSlamCameraOrientation\n");
1041#endif
1042
1043 BtQuaternion quat = ArManager::GetInstance()->GetSlamCameraOrientation();
1044
1045 int tupleQuat = MMmalloc(m, 4, TYPETAB);
1046 if (tupleQuat == NIL)
1047 {
1048 MMpush(m, NIL);
1049 return 0;
1050 }
1051
1052 MMstore(m, tupleQuat, 0, FTOM(quat.x));
1053 MMstore(m, tupleQuat, 1, FTOM(quat.y));
1054 MMstore(m, tupleQuat, 2, FTOM(quat.z));
1055 MMstore(m, tupleQuat, 3, FTOM(quat.w));
1056 MMpush(m, PTOM(tupleQuat));
1057 return 0;
1058}
1059
1067int _IsSlamFound(mmachine m)
1068{
1069#ifdef _SCOL_DEBUG_
1070 MMechostr(MSKDEBUG, "_IsSlamFound\n");
1071#endif
1072
1073 bool state = ArManager::GetInstance()->IsSlamFound();
1074 MMpush(m, ITOM((state) ? 1 : 0));
1075
1076 return 0;
1077}
1078
1086int _ResetSlamDetector(mmachine m)
1087{
1088#ifdef _SCOL_DEBUG_
1089 MMechostr(MSKDEBUG, "_IsSlamFound\n");
1090#endif
1091
1092 ArManager::GetInstance()->ResetSlamDetector();
1093 MMpush(m, ITOM(1));
1094
1095 return 0;
1096}
1097#endif
1098
1099/*******************************************
1100* AR MARKER
1101********************************************/
1102
1103int destroyMarkerObj(mmachine m, SCOL_PTR_TYPE handsys, int obj)
1104{
1105 ArMarker* MarkerOBJ = MMgetPointer<ArMarker*>(m, MTOP(obj));
1107
1108 MMsetPointer<ArMarker*>(m, MTOP(obj), 0);
1109
1110 MMechostr(MSKDEBUG, "ArMarker destroyed.\n");
1111 return 0;
1112}
1113
1122int _DSarMarker(mmachine m)
1123{
1124#ifdef _SCOL_DEBUG_
1125 MMechostr(MSKDEBUG, "_DSarMarker\n");
1126#endif
1127
1128 int obj = MMget(m, 0);
1129 if (obj == NIL)
1130 {
1131 MMset(m, 0, NIL);
1132 return 0;
1133 }
1134
1135 OBJdelTM(m, OBJMARKERSCOL, obj);
1136
1137 MMset(m, 0, ITOM(0));
1138
1139#ifdef _SCOL_DEBUG_
1140 MMechostr(MSKDEBUG, "ok\n");
1141#endif
1142 return 0;
1143}
1144
1155int _CRarMarker(mmachine m)
1156{
1157#ifdef _SCOL_DEBUG_
1158 MMechostr(MSKDEBUG, "_CRarMarker\n");
1159#endif
1160
1161 int iSize = MMpull(m);
1162 int idx = MMpull(m);
1163 if ((idx == NIL) || (iSize == NIL) || (MTOI(idx) > 1022) || (MTOI(idx) < 0))
1164 {
1165 MMset(m, 0, NIL);
1166 return 0;
1167 }
1168
1169 // Get the channel without pulling it (first element in the stack)
1170 int channel = MMget(m, 0);
1171
1172 // Test the channel
1173 if (channel == NIL)
1174 {
1175 MMechostr(MSKRUNTIME, "_CRarMarker : Channel NIL\n");
1176 return 0;
1177 }
1178
1179 ArMarker* MarkerOBJ = ArManager::GetInstance()->AddMarker(MTOI(idx), MTOF(iSize));
1180
1181 if (!MarkerOBJ)
1182 {
1183 MMechostr(MSKDEBUG, "Failed to create marker\n");
1184 MMset(m, 0, NIL);
1185 return 0;
1186 }
1187
1188 if ((MMpushPointer(m, MarkerOBJ) != 0))
1189 {
1191 MMset(m, 0, NIL);
1192 return MERRMEM;
1193 }
1194
1195#ifdef _SCOL_DEBUG_
1196 MMechostr(MSKDEBUG, "ok\n");
1197#endif
1198 return OBJcreate(m, OBJMARKERSCOL, SCOL_PTR MarkerOBJ, NIL, 0);
1199}
1200
1211int _CRarMarkerFromFile(mmachine m)
1212{
1213#ifdef _SCOL_DEBUG_
1214 MMechostr(MSKDEBUG, "_CRarMarkerFromFile\n");
1215#endif
1216
1217 int iSize = MMpull(m);
1218 int ifile = MMpull(m);
1219 if ((ifile == NIL) || (iSize == NIL))
1220 {
1221 MMset(m, 0, NIL);
1222 return 0;
1223 }
1224
1225 // Get the channel without pulling it (first element in the stack)
1226 int channel = MMget(m, 0);
1227
1228 // Test the channel
1229 if (channel == NIL)
1230 {
1231 MMechostr(MSKRUNTIME, "_CRarMarkerFromFile : Channel NIL\n");
1232 return 0;
1233 }
1234
1235 ArMarker* MarkerOBJ = ArManager::GetInstance()->AddMarker(MMstartstr(m, MTOP(ifile)), MTOF(iSize));
1236
1237 if (!MarkerOBJ)
1238 {
1239 MMechostr(MSKDEBUG, "Failed to create marker\n");
1240 MMset(m, 0, NIL);
1241 return 0;
1242 }
1243
1244 if ((MMpushPointer(m, MarkerOBJ) != 0))
1245 {
1247 MMset(m, 0, NIL);
1248 return MERRMEM;
1249 }
1250
1251#ifdef _SCOL_DEBUG_
1252 MMechostr(MSKDEBUG, "ok\n");
1253#endif
1254 return OBJcreate(m, OBJMARKERSCOL, SCOL_PTR MarkerOBJ, NIL, 0);
1255}
1256
1269{
1270#ifdef _SCOL_DEBUG_
1271 MMechostr(MSKDEBUG, "_CRarMarkerFromFileEx\n");
1272#endif
1273
1274 int iMaxFeatures = MMpull(m);
1275 int iSize = MMpull(m);
1276 int ifile = MMpull(m);
1277 if (iSize == NIL)
1278 {
1279 MMset(m, 0, NIL);
1280 return 0;
1281 }
1282
1283 std::string path = "";
1284 if (ifile != NIL)
1285 path = MMstartstr(m, MTOP(ifile));
1286
1287 ArMarker* MarkerOBJ = ArManager::GetInstance()->AddMarker(path, MTOF(iSize), MTOI(iMaxFeatures));
1288
1289 if (!MarkerOBJ)
1290 {
1291 MMechostr(MSKDEBUG, "Failed to create marker\n");
1292 MMset(m, 0, NIL);
1293 return 0;
1294 }
1295
1296 if ((MMpushPointer(m, MarkerOBJ) != 0))
1297 {
1299 MMset(m, 0, NIL);
1300 return MERRMEM;
1301 }
1302
1303#ifdef _SCOL_DEBUG_
1304 MMechostr(MSKDEBUG, "ok\n");
1305#endif
1306 return OBJcreate(m, OBJMARKERSCOL, SCOL_PTR MarkerOBJ, NIL, 0);
1307}
1308
1322{
1323#ifdef _SCOL_DEBUG_
1324 MMechostr(MSKDEBUG, "_CRarMarkerFromFileEx2\n");
1325#endif
1326
1327 int iuser = MMpull(m);
1328 int iCbk = MMpull(m);
1329 int iMaxFeatures = MMpull(m);
1330 int iSize = MMpull(m);
1331 int ifile = MMpull(m);
1332 if ((ifile == NIL) || (iSize == NIL))
1333 {
1334 MMset(m, 0, NIL);
1335 return 0;
1336 }
1337
1338 // Get the channel without pulling it (first element in the stack)
1339 int channel = MMget(m, 0);
1340
1341 // Test the channel
1342 if (channel == NIL)
1343 {
1344 MMechostr(MSKRUNTIME, "_CRarMarkerFromFileEx2 : Channel NIL\n");
1345 return 0;
1346 }
1347
1348 ArMarker* MarkerOBJ = ArManager::GetInstance()->AddMarker(MMstartstr(m, MTOP(ifile)), MTOF(iSize), MTOI(iMaxFeatures));
1349
1350 if (!MarkerOBJ)
1351 {
1352 MMechostr(MSKDEBUG, "Failed to create marker\n");
1353 MMset(m, 0, NIL);
1354 return 0;
1355 }
1356
1357 if ((MMpushPointer(m, MarkerOBJ) != 0))
1358 {
1360 MMset(m, 0, NIL);
1361 return MERRMEM;
1362 }
1363
1364 int k = OBJcreate(m, OBJMARKERSCOL, SCOL_PTR MarkerOBJ, NIL, 0);
1365
1366 if ((k = MMpush(m, iCbk))) return k; /* reading callback */
1367 if ((k = MMpush(m, iuser))) return k; /* user param */
1368 if ((k = OBJaddreflex(m, OBJMARKERSCOL, SCOL_AR_MARKER_TRAINNED_CB))) return k;
1369
1370#ifdef _SCOL_DEBUG_
1371 MMechostr(MSKDEBUG, "ok\n");
1372#endif
1373 return k;
1374}
1375
1385int _CRarMarkerFromFace(mmachine m)
1386{
1387#ifdef _SCOL_DEBUG_
1388 MMechostr(MSKDEBUG, "_CRarMarkerFromFace\n");
1389#endif
1390
1391 int iSize = MMpull(m);
1392 if (iSize == NIL)
1393 {
1394 MMset(m, 0, NIL);
1395 return 0;
1396 }
1397
1398 ArMarker* MarkerOBJ = ArManager::GetInstance()->AddFaceMarker(MTOF(iSize));
1399
1400 if (!MarkerOBJ)
1401 {
1402 MMechostr(MSKDEBUG, "Failed to create marker\n");
1403 MMset(m, 0, NIL);
1404 return 0;
1405 }
1406
1407 if ((MMpushPointer(m, MarkerOBJ) != 0))
1408 {
1410 MMset(m, 0, NIL);
1411 return MERRMEM;
1412 }
1413
1414#ifdef _SCOL_DEBUG_
1415 MMechostr(MSKDEBUG, "ok\n");
1416#endif
1417 return OBJcreate(m, OBJMARKERSCOL, SCOL_PTR MarkerOBJ, NIL, 0);
1418}
1419
1430int _UPDATEarMarkers(mmachine m)
1431{
1432#ifdef _SCOL_DEBUG_
1433 MMechostr(MSKDEBUG, "_UPDATEarMarkers\n");
1434#endif
1435
1436 int idebug = MMpull(m);
1437 int imirror = MMpull(m);
1438 int iarcameraparam = MMpull(m);
1439 int bitmap = MMget(m, 0);
1440
1441 if ((bitmap == NIL) || (iarcameraparam == NIL))
1442 {
1443 MMset(m, 0, NIL);
1444 return 0;
1445 }
1446
1447 PtrObjVoid OB = (PtrObjVoid)MMstart(m, MTOP(bitmap));
1448 PtrObjBitmap B = (PtrObjBitmap)MMstart(m, MTOP(OB->Buffer));
1449
1450 if (B->bits == 0)
1451 {
1452 MMset(m, 0, NIL);
1453 return 0;
1454 }
1455
1456 cv::Mat imagesrc(B->TailleH, B->TailleW, CV_8UC3);
1458
1459 bool revert = false;
1460 if ((imirror != NIL) && (MTOI(imirror) == 1))
1461 revert = true;
1462
1463 bool debug = false;
1464 if ((idebug != NIL) && (MTOI(idebug) == 1))
1465 debug = true;
1466
1467 ArCameraParam* arcameraparam = MMgetPointer<ArCameraParam*>(m, MTOP(iarcameraparam));
1468 if (arcameraparam == 0)
1469 {
1470 MMset(m, 0, NIL);
1471 return 0;
1472 }
1473
1474 ArManager::GetInstance()->UpdateMarkers(imagesrc, arcameraparam, revert, debug);
1475
1476 if (debug)
1477 memcpy(B->bits, imagesrc.data, ((B->TailleW * B->TailleH) * 3));
1478
1479#ifdef _SCOL_DEBUG_
1480 MMechostr(MSKDEBUG, "ok\n");
1481#endif
1482 return 0;
1483}
1484
1485
1500{
1501#ifdef _SCOL_DEBUG_
1502 MMechostr(MSKDEBUG, "_UPDATEarMarkersBuff\n");
1503#endif
1504
1505 int idebug = MMpull(m);
1506 int imirror = MMpull(m);
1507 int iarcameraparam = MMpull(m);
1508 int ibitsperpixel = MMpull(m);
1509 int iheight = MMpull(m);
1510 int iwidth = MMpull(m);
1511 int iBuff = MMget(m, 0);
1512
1513 if ((iBuff == NIL) || (iarcameraparam == NIL) || (iwidth == NIL) || (iheight == NIL) || (ibitsperpixel == NIL))
1514 {
1515 MMset(m, 0, NIL);
1516 return 0;
1517 }
1518
1519 unsigned char* buffer = MMgetPointer<unsigned char*>(m, MTOP(iBuff));
1520 if (buffer == NULL)
1521 {
1522 MMset(m, 0, NIL);
1523 return 0;
1524 }
1525
1526 cv::Mat imagesrc = ConversionTools::ScolBitmapBufferToMat((void*)buffer, MTOI(iwidth), MTOI(iheight), MTOI(ibitsperpixel), false);
1527
1528 bool revert = false;
1529 if ((imirror != NIL) && (MTOI(imirror) == 1))
1530 revert = true;
1531
1532 bool debug = false;
1533 if ((idebug != NIL) && (MTOI(idebug) == 1))
1534 debug = true;
1535
1536 ArCameraParam* arcameraparam = MMgetPointer<ArCameraParam*>(m, MTOP(iarcameraparam));
1537 if (arcameraparam == 0)
1538 {
1539 MMset(m, 0, NIL);
1540 return 0;
1541 }
1542
1543 ArManager::GetInstance()->UpdateMarkers(imagesrc, arcameraparam, revert, debug);
1544
1545#ifdef _SCOL_DEBUG_
1546 MMechostr(MSKDEBUG, "ok\n");
1547#endif
1548 return 0;
1549}
1550
1560int _GETarMarkerBitmap(mmachine m)
1561{
1562#ifdef _SCOL_DEBUG_
1563 MMechostr(MSKDEBUG, "_GETarMarkerBitmap\n");
1564#endif
1565
1566 int ssize = MMpull(m);
1567 int markerTab = MMpull(m);
1568 if (markerTab == NIL)
1569 {
1570 MMset(m, 0, NIL);
1571 return 0;
1572 }
1573
1574 ArMarker* arMarker = MMgetPointer<ArMarker*>(m, MTOP(markerTab));
1575 if (arMarker == 0)
1576 {
1577 MMset(m, 0, NIL);
1578 return 0;
1579 }
1580
1581 int size = 16;
1582 if ((ssize != NIL) && (MTOI(ssize) > 7))
1583 size = MTOI(ssize);
1584
1585 cv::Mat mbitmap = arMarker->GetMarkerBitmap(size);
1586
1587 //create scol bitmap
1588 //stack : channel
1589
1590 cv::resize(mbitmap, mbitmap, cv::Size(size, size));
1591
1592 //push the size w h
1593 MMpush(m, ITOM(size));
1594 MMpush(m, ITOM(size));
1595
1596 //stack : channel sizew sizeh
1597 //push _CRbitmap
1598 if ((MMpush(m, Msearchinsyspak(m, "_CRbitmap"))) < 0)
1599 {
1600 MMechostr(0, "\n_GETarMarkerBitmap : error interpreting _CRbitmap");
1601 MMpull(m);
1602 MMpull(m);
1603 MMset(m, 0, NIL);
1604 return 0;
1605 }
1606
1607 //execute scol cmd
1608 Minterpreter(m);
1609
1610 int objbmp = MMget(m, 0);
1611 if (objbmp == NIL)
1612 {
1613 MMset(m, 0, NIL);
1614 return 0;
1615 }
1616
1617 PtrObjVoid OB = (PtrObjVoid)MMstart(m, MTOP(objbmp));
1618 PtrObjBitmap B = (PtrObjBitmap)MMstart(m, MTOP(OB->Buffer));
1619
1620 if (B->bits == 0)
1621 {
1622 MMset(m, 0, NIL);
1623 return 0;
1624 }
1625
1626 // create some temp variables
1627 int x = 0;
1628 int y = 0;
1629 int byteSRC = 0;
1630 int byteDST = 0;
1631
1632 // traverse all pixels...
1633 for (y = 0; y < B->TailleH; y++)
1634 for (x = 0; x < B->TailleW; x++)
1635 {
1636 byteSRC = x + y * B->TailleW; // original has only 1 channels
1637 byteDST = x * B->BytesPP + y * B->BPL;
1638
1639 // copy 3 bytes from source to destination
1640 B->bits[byteDST] = mbitmap.data[byteSRC];//b
1641 B->bits[byteDST + 1] = mbitmap.data[byteSRC];//g
1642 B->bits[byteDST + 2] = mbitmap.data[byteSRC];//r
1643 }
1644
1645#ifdef _SCOL_DEBUG_
1646 MMechostr(MSKDEBUG, "ok\n");
1647#endif
1648 return 0;
1649}
1650
1659{
1660#ifdef _SCOL_DEBUG_
1661 MMechostr(MSKDEBUG, "_GETarMarkerPosition\n");
1662#endif
1663
1664 int markerTab = MMget(m, 0);
1665 if (markerTab == NIL)
1666 {
1667 MMset(m, 0, NIL);
1668 return 0;
1669 }
1670
1671 ArMarker* arMarker = MMgetPointer<ArMarker*>(m, MTOP(markerTab));
1672 if (arMarker == 0)
1673 {
1674 MMset(m, 0, NIL);
1675 return 0;
1676 }
1677
1678 Vector3 markerPosition = arMarker->GetPosition();
1679
1680 int tuplePos = MMmalloc(m, 3, TYPETAB);
1681 if (tuplePos == NIL)
1682 {
1683 MMset(m, 0, NIL);
1684 return 0;
1685 }
1686
1687 MMstore(m, tuplePos, 0, FTOM(markerPosition.x));
1688 MMstore(m, tuplePos, 1, FTOM(markerPosition.y));
1689 MMstore(m, tuplePos, 2, FTOM(markerPosition.z));
1690 MMset(m, 0, PTOM(tuplePos));
1691
1692#ifdef _SCOL_DEBUG_
1693 MMechostr(MSKDEBUG, "ok\n");
1694#endif
1695 return 0;
1696}
1697
1706{
1707#ifdef _SCOL_DEBUG_
1708 MMechostr(MSKDEBUG, "_GETarMarkerPixelPosition\n");
1709#endif
1710
1711 int markerTab = MMget(m, 0);
1712 if (markerTab == NIL)
1713 {
1714 MMset(m, 0, NIL);
1715 return 0;
1716 }
1717
1718 ArMarker* arMarker = MMgetPointer<ArMarker*>(m, MTOP(markerTab));
1719 if (arMarker == 0)
1720 {
1721 MMset(m, 0, NIL);
1722 return 0;
1723 }
1724
1725 Vector3 markerPosition = arMarker->GetPixelPosition();
1726
1727 int tuplePos = MMmalloc(m, 3, TYPETAB);
1728 if (tuplePos == NIL)
1729 {
1730 MMset(m, 0, NIL);
1731 return 0;
1732 }
1733
1734 MMstore(m, tuplePos, 0, ITOM((int)markerPosition.x));
1735 MMstore(m, tuplePos, 1, ITOM((int)markerPosition.y));
1736 MMstore(m, tuplePos, 2, ITOM((int)markerPosition.z));
1737 MMset(m, 0, PTOM(tuplePos));
1738
1739#ifdef _SCOL_DEBUG_
1740 MMechostr(MSKDEBUG, "ok\n");
1741#endif
1742 return 0;
1743}
1744
1753{
1754#ifdef _SCOL_DEBUG_
1755 MMechostr(MSKDEBUG, "_GETarMarkerOrientation\n");
1756#endif
1757
1758 int markerTab = MMget(m, 0);
1759 if (markerTab == NIL)
1760 {
1761 MMset(m, 0, NIL);
1762 return 0;
1763 }
1764
1765 ArMarker* arMarker = MMgetPointer<ArMarker*>(m, MTOP(markerTab));
1766 if (arMarker == 0)
1767 {
1768 MMset(m, 0, NIL);
1769 return 0;
1770 }
1771
1772 BtQuaternion markerOrientation = arMarker->GetOrientation();
1773
1774 int tupleQuat = MMmalloc(m, 4, TYPETAB);
1775 if (tupleQuat == NIL)
1776 {
1777 MMset(m, 0, NIL);
1778 return 0;
1779 }
1780
1781 MMstore(m, tupleQuat, 0, FTOM(markerOrientation.x));
1782 MMstore(m, tupleQuat, 1, FTOM(markerOrientation.y));
1783 MMstore(m, tupleQuat, 2, FTOM(markerOrientation.z));
1784 MMstore(m, tupleQuat, 3, FTOM(markerOrientation.w));
1785 MMset(m, 0, PTOM(tupleQuat));
1786
1787#ifdef _SCOL_DEBUG_
1788 MMechostr(MSKDEBUG, "ok\n");
1789#endif
1790 return 0;
1791}
1792
1800int _ISarMarkerVisible(mmachine m)
1801{
1802#ifdef _SCOL_DEBUG_
1803 MMechostr(MSKDEBUG, "_ISarMarkerVisible\n");
1804#endif
1805
1806 int markerTab = MMget(m, 0);
1807 if (markerTab == NIL)
1808 {
1809 MMset(m, 0, NIL);
1810 return 0;
1811 }
1812
1813 ArMarker* arMarker = MMgetPointer<ArMarker*>(m, MTOP(markerTab));
1814 if (arMarker == 0)
1815 {
1816 MMset(m, 0, NIL);
1817 return 0;
1818 }
1819
1820 int visible = (arMarker->IsVisible()) ? 1 : 0;
1821
1822 MMset(m, 0, ITOM(visible));
1823
1824#ifdef _SCOL_DEBUG_
1825 MMechostr(MSKDEBUG, "ok\n");
1826#endif
1827 return 0;
1828}
1829
1837int _GETarMarkerSize(mmachine m)
1838{
1839#ifdef _SCOL_DEBUG_
1840 MMechostr(MSKDEBUG, "_GETarMarkerSize\n");
1841#endif
1842
1843 int markerTab = MMget(m, 0);
1844 if (markerTab == NIL)
1845 {
1846 MMset(m, 0, NIL);
1847 return 0;
1848 }
1849
1850 ArMarker* arMarker = MMgetPointer<ArMarker*>(m, MTOP(markerTab));
1851 if (arMarker == 0)
1852 {
1853 MMset(m, 0, NIL);
1854 return 0;
1855 }
1856
1857 float size = arMarker->GetSize();
1858
1859 MMset(m, 0, FTOM(size));
1860
1861#ifdef _SCOL_DEBUG_
1862 MMechostr(MSKDEBUG, "ok\n");
1863#endif
1864 return 0;
1865}
1866
1875int _SETarMarkerSize(mmachine m)
1876{
1877#ifdef _SCOL_DEBUG_
1878 MMechostr(MSKDEBUG, "_SETarMarkerSize\n");
1879#endif
1880
1881 int isize = MMpull(m);
1882 int markerTab = MMget(m, 0);
1883 if ((markerTab == NIL) || (isize == NIL))
1884 {
1885 MMset(m, 0, NIL);
1886 return 0;
1887 }
1888
1889 ArMarker* arMarker = MMgetPointer<ArMarker*>(m, MTOP(markerTab));
1890 if (arMarker == 0)
1891 {
1892 MMset(m, 0, NIL);
1893 return 0;
1894 }
1895
1896 float size = MTOF(isize);
1897 if (size <= 0.0f)
1898 {
1899 MMset(m, 0, NIL);
1900 MMechostr(MSKRUNTIME, "_SETarMarkerSize : The marker size can not be inferior or equal to 0.\n");
1901 return 0;
1902 }
1903
1904 arMarker->SetSize(size);
1905
1906 MMset(m, 0, ITOM(0));
1907
1908#ifdef _SCOL_DEBUG_
1909 MMechostr(MSKDEBUG, "ok\n");
1910#endif
1911 return 0;
1912}
1913
1914
1927{
1928#ifdef _SCOL_DEBUG_
1929 MMechostr(MSKDEBUG, "_SETarMarkerFromPictureZone\n");
1930#endif
1931
1932 int iHeight = MMpull(m);
1933 int iWidth = MMpull(m);
1934 int iY = MMpull(m);
1935 int iX = MMpull(m);
1936 int markerTab = MMget(m, 0);
1937
1938 if ((markerTab == NIL) || (iX == NIL) || (iY == NIL) || (iWidth == NIL) || (iHeight == NIL))
1939 {
1940 MMset(m, 0, NIL);
1941 return 0;
1942 }
1943
1944 ArMarker* arMarker = MMgetPointer<ArMarker*>(m, MTOP(markerTab));
1945 if (arMarker == 0)
1946 {
1947 MMset(m, 0, NIL);
1948 return 0;
1949 }
1950
1951 if (arMarker->GetType() == ArMarker::AR_FFT_MARKER)
1952 {
1953 ArFeaturedMarker* fftmarker = static_cast<ArFeaturedMarker*> (arMarker);
1954 fftmarker->RegisterNextFrame(cv::Point(MTOI(iX), MTOI(iY)), cv::Size(MTOI(iWidth), MTOI(iHeight)));
1955 }
1956 else if (arMarker->GetType() == ArMarker::AR_ARTK_FFT_MARKER)
1957 {
1958 ArTkMarker* fftmarker = static_cast<ArTkMarker*> (arMarker);
1959 fftmarker->RegisterNextFrame(cv::Point(MTOI(iX), MTOI(iY)), cv::Size(MTOI(iWidth), MTOI(iHeight)));
1960 }
1961 else
1962 {
1963 MMset(m, 0, NIL);
1964 return 0;
1965 }
1966
1967 MMset(m, 0, ITOM(0));
1968
1969#ifdef _SCOL_DEBUG_
1970 MMechostr(MSKDEBUG, "ok\n");
1971#endif
1972 return 0;
1973}
1974
1975
1985{
1986#ifdef _SCOL_DEBUG_
1987 MMechostr(MSKDEBUG, "_GETarMarkerWarpedBitmap\n");
1988#endif
1989
1990 /* Get stack data*/
1991 int bitmap = MMpull(m);
1992 int markerTab = MMget(m, 0);
1993
1994 if ((bitmap == NIL) || (markerTab == NIL))
1995 {
1996 MMset(m, 0, NIL);
1997 return 0;
1998 }
1999
2000 ArMarker* arMarker = MMgetPointer<ArMarker*>(m, MTOP(markerTab));
2001 if (arMarker == 0)
2002 {
2003 MMset(m, 0, NIL);
2004 return 0;
2005 }
2006
2007 PtrObjVoid OB = (PtrObjVoid)MMstart(m, MTOP(bitmap));
2008 PtrObjBitmap B = (PtrObjBitmap)MMstart(m, MTOP(OB->Buffer));
2009
2010 if (B->bits == 0)
2011 {
2012 MMset(m, 0, NIL);
2013 return 0;
2014 }
2015
2016 cv::Mat warped;
2017 if (arMarker->GetType() == ArMarker::AR_FFT_MARKER)
2018 {
2019 ArFeaturedMarker* fftmarker = static_cast<ArFeaturedMarker*> (arMarker);
2020 if (!fftmarker->GetWarpedMarker(warped))
2021 {
2022 MMset(m, 0, NIL);
2023 return 0;
2024 }
2025 }
2026 else if (arMarker->GetType() == ArMarker::AR_ARTK_FFT_MARKER)
2027 {
2028 ArTkMarker* fftmarker = static_cast<ArTkMarker*> (arMarker);
2029 if (!fftmarker->GetWarpedMarker(warped))
2030 {
2031 MMset(m, 0, NIL);
2032 return 0;
2033 }
2034 }
2035 else
2036 {
2037 MMset(m, 0, NIL);
2038 return 0;
2039 }
2040
2041 if (B->TailleW != warped.cols || B->TailleH != warped.rows)
2042 cv::resize(warped, warped, cv::Size(B->TailleW, B->TailleH), 0, 0, cv::INTER_LINEAR);
2043
2045
2046 MMset(m, 0, ITOM(0));
2047
2048#ifdef _SCOL_DEBUG_
2049 MMechostr(MSKDEBUG, "ok\n");
2050#endif
2051 return 0;
2052}
2053
2063{
2064#ifdef _SCOL_DEBUG_
2065 MMechostr(MSKDEBUG, "_SAVEarMarkerTrainnedData\n");
2066#endif
2067
2068 /* Get stack data*/
2069 int ifile = MMpull(m);
2070 int markerTab = MMget(m, 0);
2071
2072 if ((ifile == NIL) || (markerTab == NIL))
2073 {
2074 MMset(m, 0, NIL);
2075 return 0;
2076 }
2077
2078 ArMarker* arMarker = MMgetPointer<ArMarker*>(m, MTOP(markerTab));
2079 if ((arMarker == 0) || (arMarker->GetType() != ArMarker::AR_ARTK_FFT_MARKER))
2080 {
2081 MMset(m, 0, NIL);
2082 return 0;
2083 }
2084 std::string fpath = MMstartstr(m, MTOP(ifile));
2085
2086 ArTkMarker* fftmarker = static_cast<ArTkMarker*> (arMarker);
2087 if (fftmarker->SaveData(fpath))
2088 MMset(m, 0, ITOM(0));
2089 else
2090 MMset(m, 0, NIL);
2091
2092#ifdef _SCOL_DEBUG_
2093 MMechostr(MSKDEBUG, "ok\n");
2094#endif
2095 return 0;
2096}
2097
2098int getArMarkerTrainnedCb(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
2099{
2100 int k = 0;
2101 ArMarker* marker = (ArMarker*)id;
2102
2103 if (!marker)
2104 return 0;
2105
2106 // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
2107 if (OBJbeginreflex(m, OBJMARKERSCOL, SCOL_PTR marker, SCOL_AR_MARKER_TRAINNED_CB))
2108 return 0;
2109
2110 MMpush(m, ITOM((int)param));
2111
2112 k = OBJcallreflex(m, 1);
2113 return k;
2114}
2115
2116/*
2117*********************************************
2118* SCOL PART
2119*********************************************
2120*/
2121
2122/*Declaration*/
2123NativeDefinition base_ar_tk[] = {
2124 { "ObjArMarker", TYPTYPE, NULL, NULL },
2125 { "ObjArCameraParam", TYPTYPE, NULL, NULL },
2126 { "ObjBlobDetector", TYPTYPE, NULL, NULL },
2127 { "_CRarMarker", 3, "fun [Chn I F] ObjArMarker", _CRarMarker },
2128 { "_CRarMarkerFromFile", 3, "fun [Chn P F] ObjArMarker", _CRarMarkerFromFile },
2129 { "_CRarMarkerFromFileEx", 4, "fun [Chn P F I] ObjArMarker", _CRarMarkerFromFileEx },
2130 { "_CRarMarkerFromFileEx2", 6, "fun [Chn P F I fun[ObjArMarker u0 I] u1 u0] ObjArMarker", _CRarMarkerFromFileEx2 },
2131 { "_CRarMarkerFromFace", 2, "fun [Chn F] ObjArMarker", _CRarMarkerFromFace },
2132 { "_DSarMarker", 1, "fun [ObjArMarker] I", _DSarMarker },
2133 { "_SAVEarMarkerTrainnedData", 2, "fun [ObjArMarker W] I", _SAVEarMarkerTrainnedData },
2134 { "_UPDATEarMarkers", 4, "fun [ObjBitmap ObjArCameraParam I I] ObjBitmap", _UPDATEarMarkers },
2135 { "_UPDATEarMarkersBuff", 7, "fun [ObjBuff I I I ObjArCameraParam I I] ObjBuff", _UPDATEarMarkersBuff },
2136 { "_GETarMarkerBitmap", 3, "fun [Chn ObjArMarker I] ObjBitmap", _GETarMarkerBitmap },
2137 { "_GETarMarkerPosition", 1, "fun [ObjArMarker] [F F F]", _GETarMarkerPosition },
2138 { "_GETarMarkerPixelPosition", 1, "fun [ObjArMarker] [I I I]", _GETarMarkerPixelPosition },
2139 { "_GETarMarkerOrientation", 1, "fun [ObjArMarker] [F F F F]", _GETarMarkerOrientation },
2140 { "_ISarMarkerVisible", 1, "fun [ObjArMarker] I", _ISarMarkerVisible },
2141 { "_CRarCameraParam", 6, "fun [Chn I I F F P] ObjArCameraParam", _CRarCameraParam },
2142 { "_CRarCameraParamIntrinsics", 7, "fun [Chn I I F F [F F] [F F]] ObjArCameraParam", _CRarCameraParamIntrinsics },
2143 { "_DSarCameraParam", 1, "fun [ObjArCameraParam] I", _DSarCameraParam },
2144 { "_SETcameraSensorsQuat", 2, "fun [ObjArCameraParam [F F F F]] ObjArCameraParam", _SETcameraSensorsQuat },
2145 { "_AddcameraSensorsImu", 4, "fun [ObjArCameraParam [F F F] [F F F] F] ObjArCameraParam", _AddcameraSensorsImu },
2146 { "_SETcameraOffset", 2, "fun [ObjArCameraParam [F F F]] ObjArCameraParam", _SETcameraOffset },
2147 { "_GETcameraOffset", 1, "fun [ObjArCameraParam] [F F F]", _GETcameraOffset },
2148 { "_GETarProjectionMatrix", 3, "fun [ObjArCameraParam I I] [[F F F F] [F F F F] [F F F F] [F F F F]]", _GETarProjectionMatrix },
2149 { "_GETarMarkerSize", 1, "fun [ObjArMarker] F", _GETarMarkerSize },
2150 { "_SETarMarkerSize", 2, "fun [ObjArMarker F] I", _SETarMarkerSize },
2151 { "_SETarMarkerFromPictureZone",5, "fun [ObjArMarker I I I I] I", _SETarMarkerFromPictureZone },
2152 { "_GETarMarkerWarpedBitmap", 2, "fun [ObjArMarker ObjBitmap] I", _GETarMarkerWarpedBitmap },
2153 { "_CRblobDetector", 9, "fun [Chn I I [I I I] [I I I] [I F F] [I I] [I F F] [I F F]] ObjBlobDetector", _CRblobDetector },
2154 { "_DSblobDetector", 1, "fun [ObjBlobDetector] I", _DSblobDetector },
2155 { "_GETdetectedBlobs", 1, "fun [ObjBlobDetector] [[I I F] r1]", _GETdetectedBlobs },
2156 { "_GETblobDetectorSize", 1, "fun [ObjBlobDetector] [I I]", _GETblobDetectorSize }
2157
2158#ifdef HAVE_BTSLAM
2159 ,{ "_SetSlamDetectorState", 1, "fun [I] I", _SetSlamDetectorState },
2160 { "_GetSlamCameraPosition", 0, "fun [] [F F F]", _GetSlamCameraPosition },
2161 { "_GetSlamCameraOrientation", 0, "fun [] [F F F F]", _GetSlamCameraOrientation },
2162 { "_IsSlamFound", 0, "fun [] I", _IsSlamFound },
2163 { "_ResetSlamDetector", 0, "fun [] I", _ResetSlamDetector },
2164 { "_SetSlamDetectorParams", 4, "fun [I I I I] I", _SetSlamDetectorParams }
2165#endif
2166};
2167
2168// Everything inside _cond and _endcond is ignored by doxygen
2170
2175int LoadArToolkit(mmachine m)
2176{
2177 int k;
2178 MMechostr(MSKDEBUG, " > Loading ArToolkit\n");
2179
2180 // initialize marker detector singleton
2182 OBJMARKERSCOL = OBJregister(NBMARKERCB, 0, destroyMarkerObj, "OBJMARKERSCOL");
2183
2184 AR_MARKER_TRAINNED_CB = OBJgetUserEvent();
2186
2187 OBJCAMERAPARAMSCOL = OBJregister(NBARCAMERAPARAM, 0, destroyArCameraParamObj, "OBJARCAMERAPARAMSCOL");
2188 OBJBLOBSCOL = OBJregister(NBBLOBCB, 0, destroyBlobObj, "OBJBLOBDETECTORSCOL");
2189
2190 k = PKhardpak2(m, "Ar_toolkit.pkg", sizeof(base_ar_tk) / sizeof(base_ar_tk[0]), base_ar_tk);
2191 MMechostr(MSKDEBUG, " > Successfully Loaded\n");
2192 return k;
2193}
2194
2199int UnloadArToolkit()
2200{
2201 MMechostr(MSKDEBUG, "\n");
2202 MMechostr(MSKDEBUG, " > Unloading ArToolkit\n");
2203
2204 // kill marker detector singleton
2206 MMechostr(MSKDEBUG, " > Successfully Unloaded\n\n");
2207 return 0;
2208}
2209
2210
int destroyArCameraParamObj(mmachine m, SCOL_PTR_TYPE handsys, int obj)
Definition ArToolkit.cpp:58
int AR_MARKER_TRAINNED_CB
Definition ArToolkit.cpp:46
int NBBLOBCB
Definition ArToolkit.cpp:44
int NBMARKERCB
Definition ArToolkit.cpp:42
int OBJBLOBSCOL
Definition ArToolkit.cpp:38
NativeDefinition base_ar_tk[]
int destroyBlobObj(mmachine m, SCOL_PTR_TYPE handsys, int obj)
int NBARCAMERAPARAM
Definition ArToolkit.cpp:43
int OBJMARKERSCOL
Definition ArToolkit.cpp:37
int OBJCAMERAPARAMSCOL
Definition ArToolkit.cpp:39
int getArMarkerTrainnedCb(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
int destroyMarkerObj(mmachine m, SCOL_PTR_TYPE handsys, int obj)
int SCOL_AR_MARKER_TRAINNED_CB
Definition ArToolkit.cpp:47
int LoadArToolkit(mmachine m)
int UnloadArToolkit()
cv::Size GetLastBufferSize()
std::vector< cv::Point3f > GetLastDotList()
void SetCameraOffset(Vector3 offset)
void SetCameraQuat(BtQuaternion quat)
void GetProjectionMatrix(double m_proj[16], cv::Size screensize)
void AddCameraImu(Vector3 gyro, Vector3 accel, double delta)
Vector3 GetCameraOffset()
static void Kill()
Definition ArManager.cpp:80
void RemoveBlobDetector(ArBlobDetector *detector)
Definition ArManager.cpp:97
ArMarker * AddFaceMarker(float size)
ArMarker * AddMarker(int index, float size)
ArBlobDetector * AddBlobDetector(cv::SimpleBlobDetector::Params params)
Definition ArManager.cpp:89
static ArManager * GetInstance()
Definition ArManager.cpp:70
void RemoveMarker(ArMarker *marker)
void UpdateMarkers(cv::Mat image, ArCameraParam *arCameraParam, bool reversedBitmap=false, bool debugDraw=false)
Vector3 GetPosition()
Definition ArMarker.cpp:72
Vector3 GetPixelPosition()
Definition ArMarker.cpp:78
bool IsVisible()
Definition ArMarker.cpp:106
@ AR_ARTK_FFT_MARKER
Definition ArMarker.h:45
@ AR_FFT_MARKER
Definition ArMarker.h:43
void SetSize(float size)
Definition ArMarker.cpp:113
float GetSize()
Definition ArMarker.cpp:119
cv::Mat GetMarkerBitmap(int size)
Definition ArMarker.cpp:47
BtQuaternion GetOrientation()
Definition ArMarker.cpp:84
MarkerType GetType()
Definition ArMarker.cpp:95
This class represents a marker. It is a vector of the fours corners ot the marker.
Definition ArTkMarker.h:51
bool GetWarpedMarker(cv::Mat &image)
bool SaveData(std::string path)
void RegisterNextFrame(cv::Point point, cv::Size size)
static cv::Mat ScolBitmapBufferToMat(void *buffer, int width, int height, int nbcomponents, bool align=true)
static void ScolBitmapToMatRGB(PtrObjBitmap scolBitmap, cv::Mat &mat)
static void MatToScolBitmapRGB(cv::Mat mat, PtrObjBitmap scolBitmap)
int _SETcameraSensorsQuat(mmachine m)
_SETcameraSensorsQuat : This function set the camera orientation from sensors Prototype: fun [ObjArCa...
int _CRarMarkerFromFileEx2(mmachine m)
_CRarMarkerFromFileEx2 : This function create a picture file and alert when the trainning is done;
int _CRblobDetector(mmachine m)
_CRblobDetector : This function create a new blob detector
int _SETarMarkerFromPictureZone(mmachine m)
_SETarMarkerFromPictureZone: This function make a featured marker to use the next input frame zone as...
int _ISarMarkerVisible(mmachine m)
_ISarMarkerVisible : This function return a marker visibility Prototype: fun [ObjArMarker] I
int _CRarMarkerFromFace(mmachine m)
_CRarMarkerFromFace : This function create a new face detection marker
int _CRarCameraParam(mmachine m)
_CRarCameraParam : This function create a new camera parameter
Definition ArToolkit.cpp:83
int _AddcameraSensorsImu(mmachine m)
_AddcameraSensorsImu : This function set the gyroscope and acceleration data from sensors for slam Pr...
int _GETarMarkerPosition(mmachine m)
_GETarMarkerPosition : This function return a marker position Prototype: fun [ObjArMarker] [F F F]
int _CRarMarkerFromFile(mmachine m)
_CRarMarkerFromFile : This function create a new marker from a data or picture file
int _DSarMarker(mmachine m)
_DSarMarker : This function destroy a capture device
int _GETcameraOffset(mmachine m)
_GETcameraOffset : This function get the camera offset for stereo cameras Prototype: fun [ObjArCamera...
int _UPDATEarMarkersBuff(mmachine m)
_UPDATEarMarkersBuff : This function update the markers states from a pixel buffer Prototype: fun [Ob...
int _GETarMarkerPixelPosition(mmachine m)
_GETarMarkerPixelPosition : This function return a marker position Prototype: fun [ObjArMarker] [I I ...
int _CRarMarker(mmachine m)
_CRarMarker : This function create a new marker with a aruco marker id
int _CRarCameraParamIntrinsics(mmachine m)
_CRarCameraParamIntrinsics : This function create a new camera parameter
int _GETdetectedBlobs(mmachine m)
_GETdetectedBlobs : This function list the current detected blobs
int _GETarMarkerSize(mmachine m)
_GETarMarkerSize: This function return a marker bitmap Prototype: fun [ObjArMarker] F
int _SAVEarMarkerTrainnedData(mmachine m)
_SAVEarMarkerTrainnedData: This function get a featured marker and save the trainned data into a data...
int _GETarMarkerWarpedBitmap(mmachine m)
_GETarMarkerWarpedBitmap: This function get a featured marker picture warped from the detected marker...
int _SETarMarkerSize(mmachine m)
_SETarMarkerSize: This function return a marker bitmap Prototype: fun [ObjArMarker F] I
int _CRarMarkerFromFileEx(mmachine m)
_CRarMarkerFromFileEx : This function create a new featured empty marker with advanced parameter
int _UPDATEarMarkers(mmachine m)
_UPDATEarMarkers : This function update the markers states Prototype: fun [ObjBitmap ObjArCameraParam...
int _DSblobDetector(mmachine m)
_DSblobDetector : This function destroy a blob detector
int _GETarMarkerBitmap(mmachine m)
_GETarMarkerBitmap : This function return a marker bitmap Prototype: fun [Chn ObjArMarker I] ObjBitma...
int _GETarProjectionMatrix(mmachine m)
_GETarProjectionMatrix : This function return the projection matrix from a camera parameter Prototype...
int _GETarMarkerOrientation(mmachine m)
_GETarMarkerOrientation : This function return a marker orientation Prototype: fun [ObjArMarker] [F F...
int _DSarCameraParam(mmachine m)
_DSarCameraParam : This function destroy a camera parameter
int _SETcameraOffset(mmachine m)
_SETcameraOffset : This function set the camera offset for stereo cameras Prototype: fun [ObjArCamera...
int _GETblobDetectorSize(mmachine m)
_GETblobDetectorSize : This function return the size of the picture used for detection