├── .gitignore
├── Main (C++)
└── Tracking
│ ├── .vs
│ └── CameraCalibration
│ │ └── v15
│ │ ├── .suo
│ │ ├── Browse.VC.db
│ │ └── ipch
│ │ ├── 149dff8fe109d98c.ipch
│ │ ├── 6ff63f364df8a143.ipch
│ │ ├── 9fa80a7436117fe1.ipch
│ │ ├── AutoPCH
│ │ ├── 603dd84932c2fede
│ │ │ └── FILTER.ipch
│ │ ├── 8bee84944920963
│ │ │ └── FILTER.ipch
│ │ ├── 8db3368d2e3403dc
│ │ │ └── FILTER.ipch
│ │ ├── 95ba7d4460899a1b
│ │ │ └── FILTER.ipch
│ │ ├── c37866ee700b2fa
│ │ │ └── FILTER.ipch
│ │ └── d19144248af3f90d
│ │ │ └── FILTER.ipch
│ │ ├── a4c328cba84aac7c.ipch
│ │ ├── cf517484386bd4c.ipch
│ │ └── ee8cf2aeaa1d42a1.ipch
│ ├── CameraCalibration.sln
│ ├── CameraCalibration
│ ├── CalibrationParams
│ ├── CalibrationParams - ELP
│ ├── CameraCalibration.vcxproj
│ ├── CameraCalibration.vcxproj.filters
│ ├── CameraCalibration.vcxproj.user
│ ├── Markers
│ │ ├── 4x4Marker_0.jpg
│ │ ├── 4x4Marker_1.jpg
│ │ ├── 4x4Marker_2.jpg
│ │ ├── 4x4Marker_3.jpg
│ │ ├── 4x4Marker_4.jpg
│ │ ├── 4x4Marker_5.jpg
│ │ ├── 4x4Marker_6.jpg
│ │ └── 4x4Marker_7.jpg
│ ├── main.cpp
│ ├── stdafx.cpp
│ ├── stdafx.h
│ ├── targetver.h
│ └── x64
│ │ ├── Debug
│ │ ├── CameraCa.4FE6E6C6.tlog
│ │ │ ├── CL.command.1.tlog
│ │ │ ├── CL.read.1.tlog
│ │ │ ├── CL.write.1.tlog
│ │ │ ├── CameraCalibration.lastbuildstate
│ │ │ ├── link.command.1.tlog
│ │ │ ├── link.read.1.tlog
│ │ │ └── link.write.1.tlog
│ │ ├── CameraCalibration.log
│ │ ├── CameraCalibration.obj
│ │ ├── CameraCalibration.pch
│ │ ├── main.obj
│ │ ├── main.obj.enc
│ │ ├── stdafx.obj
│ │ ├── vc141.idb
│ │ └── vc141.pdb
│ │ └── Release
│ │ ├── CameraCa.4FE6E6C6.tlog
│ │ ├── CL.command.1.tlog
│ │ ├── CL.read.1.tlog
│ │ ├── CL.write.1.tlog
│ │ ├── CameraCalibration.lastbuildstate
│ │ └── unsuccessfulbuild
│ │ ├── CameraCalibration.log
│ │ ├── CameraCalibration.pch
│ │ ├── stdafx.obj
│ │ └── vc141.pdb
│ └── x64
│ └── Debug
│ ├── CameraCalibration.exe
│ ├── CameraCalibration.ilk
│ └── CameraCalibration.pdb
├── Python Scripts
├── Helper
│ ├── ar_markers_generate.py
│ ├── ar_markers_scan.py
│ ├── camTest.py
│ ├── marker_only_tracking.py
│ └── marker_tracking_opencv.py
├── caputils.py
└── tracking.py
├── README.md
├── Result Pictures
├── 10 cm left 1.PNG
├── 10 cm right 1.PNG
├── 10 cm right 2.PNG
├── 10cm left 1.PNG
├── 4cm high 2.PNG
├── 4cm high.PNG
├── 8cm high 2.PNG
├── 8cm high.PNG
├── 90degrees 14 cm away 2.PNG
├── 90degrees 14 cm away.PNG
├── 90degrees 30 cm away 2.PNG
├── 90degrees 30 cm away.PNG
├── 90degrees 50 cm away 2.PNG
├── 90degrees 50 cm away.PNG
└── calibration.PNG
├── Samples
└── Pictures
│ ├── Markers
│ └── marker.jpg
│ ├── box_sample.jpg
│ ├── markerdoc.docx
│ └── markerdoc.pdf
├── environment.yml
└── temp.cpp
/.gitignore:
--------------------------------------------------------------------------------
1 | *.dll
2 | C++/Tracking/CameraCalibration/opencv_world341d.dll
3 | temp.cpp
4 |
--------------------------------------------------------------------------------
/Main (C++)/Tracking/.vs/CameraCalibration/v15/.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/.vs/CameraCalibration/v15/.suo
--------------------------------------------------------------------------------
/Main (C++)/Tracking/.vs/CameraCalibration/v15/Browse.VC.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/.vs/CameraCalibration/v15/Browse.VC.db
--------------------------------------------------------------------------------
/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/149dff8fe109d98c.ipch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/149dff8fe109d98c.ipch
--------------------------------------------------------------------------------
/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/6ff63f364df8a143.ipch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/6ff63f364df8a143.ipch
--------------------------------------------------------------------------------
/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/9fa80a7436117fe1.ipch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/9fa80a7436117fe1.ipch
--------------------------------------------------------------------------------
/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/AutoPCH/603dd84932c2fede/FILTER.ipch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/AutoPCH/603dd84932c2fede/FILTER.ipch
--------------------------------------------------------------------------------
/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/AutoPCH/8bee84944920963/FILTER.ipch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/AutoPCH/8bee84944920963/FILTER.ipch
--------------------------------------------------------------------------------
/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/AutoPCH/8db3368d2e3403dc/FILTER.ipch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/AutoPCH/8db3368d2e3403dc/FILTER.ipch
--------------------------------------------------------------------------------
/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/AutoPCH/95ba7d4460899a1b/FILTER.ipch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/AutoPCH/95ba7d4460899a1b/FILTER.ipch
--------------------------------------------------------------------------------
/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/AutoPCH/c37866ee700b2fa/FILTER.ipch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/AutoPCH/c37866ee700b2fa/FILTER.ipch
--------------------------------------------------------------------------------
/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/AutoPCH/d19144248af3f90d/FILTER.ipch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/AutoPCH/d19144248af3f90d/FILTER.ipch
--------------------------------------------------------------------------------
/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/a4c328cba84aac7c.ipch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/a4c328cba84aac7c.ipch
--------------------------------------------------------------------------------
/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/cf517484386bd4c.ipch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/cf517484386bd4c.ipch
--------------------------------------------------------------------------------
/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/ee8cf2aeaa1d42a1.ipch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/.vs/CameraCalibration/v15/ipch/ee8cf2aeaa1d42a1.ipch
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27428.2015
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CameraCalibration", "CameraCalibration\CameraCalibration.vcxproj", "{4FE6E6C6-BDD8-458F-B549-29EF3466BC42}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {4FE6E6C6-BDD8-458F-B549-29EF3466BC42}.Debug|x64.ActiveCfg = Debug|x64
17 | {4FE6E6C6-BDD8-458F-B549-29EF3466BC42}.Debug|x64.Build.0 = Debug|x64
18 | {4FE6E6C6-BDD8-458F-B549-29EF3466BC42}.Debug|x86.ActiveCfg = Debug|Win32
19 | {4FE6E6C6-BDD8-458F-B549-29EF3466BC42}.Debug|x86.Build.0 = Debug|Win32
20 | {4FE6E6C6-BDD8-458F-B549-29EF3466BC42}.Release|x64.ActiveCfg = Release|x64
21 | {4FE6E6C6-BDD8-458F-B549-29EF3466BC42}.Release|x64.Build.0 = Release|x64
22 | {4FE6E6C6-BDD8-458F-B549-29EF3466BC42}.Release|x86.ActiveCfg = Release|Win32
23 | {4FE6E6C6-BDD8-458F-B549-29EF3466BC42}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {CC14C36D-5300-4BF7-8B86-898B4A88BD34}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/CalibrationParams:
--------------------------------------------------------------------------------
1 | 3
2 | 3
3 | 507.7
4 | 0
5 | 3.00113
6 | 0
7 | 453.657
8 | 4.50012
9 | 0
10 | 0
11 | 1
12 | 5
13 | 1
14 | -0.0620087
15 | 0.000915049
16 | 0.000524769
17 | 0.00756588
18 | -3.7783e-06
19 |
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/CalibrationParams - ELP:
--------------------------------------------------------------------------------
1 | 3
2 | 3
3 | 341.212
4 | 0
5 | 3
6 | 0
7 | 986.251
8 | 4.5
9 | 0
10 | 0
11 | 1
12 | 5
13 | 1
14 | -0.0125278
15 | 2.00789e-05
16 | 0.00024988
17 | 0.00461761
18 | -8.3114e-09
19 |
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/CameraCalibration.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | 15.0
23 | {4FE6E6C6-BDD8-458F-B549-29EF3466BC42}
24 | Win32Proj
25 | CameraCalibration
26 | 10.0.16299.0
27 |
28 |
29 |
30 | Application
31 | true
32 | v141
33 | Unicode
34 |
35 |
36 | Application
37 | false
38 | v141
39 | true
40 | Unicode
41 |
42 |
43 | Application
44 | true
45 | v141
46 | Unicode
47 |
48 |
49 | Application
50 | false
51 | v141
52 | true
53 | Unicode
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | true
75 |
76 |
77 | true
78 |
79 |
80 | false
81 |
82 |
83 | false
84 |
85 |
86 |
87 | Use
88 | Level3
89 | Disabled
90 | true
91 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
92 | true
93 |
94 |
95 | Console
96 | true
97 |
98 |
99 |
100 |
101 | Use
102 | Level3
103 | Disabled
104 | true
105 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
106 | true
107 | $(OPENCV3_DIR)\include;%(AdditionalIncludeDirectories)
108 |
109 |
110 | Console
111 | true
112 | $(OPENCV3_DIR)\x64\vc15\lib;%(AdditionalLibraryDirectories)
113 | opencv_world341d.lib;opencv_core341d.lib;opencv_aruco341d.lib;opencv_imgproc341d.lib;opencv_highgui341d.lib;opencv_video341d.lib;opencv_imgcodecs341d.lib;opencv_videoio341d.lib;opencv_calib3d341d.lib;opencv_ccalib341d.lib;%(AdditionalDependencies)
114 |
115 |
116 |
117 |
118 | Use
119 | Level3
120 | MaxSpeed
121 | true
122 | true
123 | true
124 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
125 | true
126 |
127 |
128 | Console
129 | true
130 | true
131 | true
132 |
133 |
134 |
135 |
136 | Use
137 | Level3
138 | MaxSpeed
139 | true
140 | true
141 | true
142 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
143 | true
144 |
145 |
146 | Console
147 | true
148 | true
149 | true
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 | Create
160 | Create
161 | Create
162 | Create
163 |
164 |
165 |
166 |
167 |
168 |
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/CameraCalibration.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 |
26 |
27 | Source Files
28 |
29 |
30 | Source Files
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/CameraCalibration.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/Markers/4x4Marker_0.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/Markers/4x4Marker_0.jpg
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/Markers/4x4Marker_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/Markers/4x4Marker_1.jpg
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/Markers/4x4Marker_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/Markers/4x4Marker_2.jpg
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/Markers/4x4Marker_3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/Markers/4x4Marker_3.jpg
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/Markers/4x4Marker_4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/Markers/4x4Marker_4.jpg
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/Markers/4x4Marker_5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/Markers/4x4Marker_5.jpg
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/Markers/4x4Marker_6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/Markers/4x4Marker_6.jpg
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/Markers/4x4Marker_7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/Markers/4x4Marker_7.jpg
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/main.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "opencv2\opencv.hpp"
3 | #include "opencv2\core.hpp"
4 | #include "opencv2\imgproc.hpp"
5 | #include "opencv2\highgui.hpp"
6 | #include "opencv2\aruco.hpp" //contains marker functionality
7 | #include "opencv2\calib3d.hpp"
8 | #include
9 | #include
10 | #include
11 |
12 |
13 | using namespace cv;
14 | using namespace std;
15 |
16 | //enter key values in meters
17 | const float chessSquareDimension = 0.0245f;
18 | const float markerDimension = 0.05f;
19 | const float sensorWidth = 0.002f;
20 | const float sensorHeight = 0.003f;
21 | const Size chessboardSize = Size(6, 9);
22 |
23 | //Camera calibration is completed using a chessboard image in this app
24 | //please refer to opencv documentation for different calibration strategies
25 |
26 | void createMarkers()
27 | { //here the unique aruco markers are iteratively chosen from a dicitonary and saved to the working directory
28 | Mat outputMarker;
29 | //setup the predefined aruco marker dictionary (50 markers inside)
30 | Ptr markerDictionary = aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME::DICT_4X4_50);
31 |
32 | //iterate through dictionary and save up to the number of markers you want
33 | for (int i = 0; i < 8; i++)
34 | {
35 | aruco::drawMarker(markerDictionary, i, 500, outputMarker, 1); //saves the i't marker from the markerDictionary with pixel size 500x500, border width of 1 bit
36 | ostringstream convert;
37 | string img = "4x4Marker_";
38 | convert << img << i << ".jpg"; //append i to the marker name for identification
39 | imwrite(convert.str(), outputMarker);
40 | }
41 | }
42 |
43 | void createBoardPositions(Size boardSize, float squareLen, vector& corners)
44 | { //here we used a double nested loop to iterativley populate the corners vector with the locations of the squares on the board
45 | //in world space coords (i.e. meters)
46 | for (int i = 0; i < boardSize.height; i++) //loop over the board height
47 | {
48 | for (int j = 0; j < boardSize.width; j++) //loop over the board width
49 | {
50 | corners.push_back(Point3f(j * squareLen, i*squareLen, 0.0f)); //note z is zero since we have a flat plane
51 | }
52 | }
53 |
54 |
55 | }
56 |
57 | void getBoardCorners(vector images, vector>&allFoundCorners, bool showResults = false)
58 | { //so after receiving a vector full of chessboard images, we want to iterate through each one and extract the corners
59 | for (vector::iterator iter = images.begin(); iter != images.end(); iter++) {
60 |
61 | vector pointList; //vector to contain found corners
62 | bool found = findChessboardCorners(*iter, Size(9, 6), pointList, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE); //finds corners
63 |
64 | if (found)
65 | {
66 | allFoundCorners.push_back(pointList); //push corners into vector of vectors
67 | }
68 |
69 | if (showResults)
70 | {
71 | drawChessboardCorners(*iter, Size(9, 6), pointList, found); //draw corners onto image
72 | imshow("Corner Finder", *iter); //show image
73 | waitKey(0);
74 | }
75 | }
76 | }
77 |
78 | void cameraCalibration(vector calibImages, Size boardSize, float squareEdgeLength, Mat& cameraMatrix, Mat& distortionCoeffs)
79 | { //calibrates the camera using getBoardCorners and createBoardPositions
80 | vector> boardImgSpacePoints;
81 | getBoardCorners(calibImages, boardImgSpacePoints, false); //get board corners which will populate boardImgSpacePoints
82 |
83 | vector> boardWorldSpacePoints(1); //known board positions for each image (in real 3d space), initially of size 1
84 | createBoardPositions(boardSize, squareEdgeLength, boardWorldSpacePoints[0]);
85 | boardWorldSpacePoints.resize(boardImgSpacePoints.size(), boardWorldSpacePoints[0]);
86 |
87 | vector rVectors, tVectors;
88 | distortionCoeffs = Mat::zeros(8, 1, CV_64F);
89 |
90 | calibrateCamera(boardWorldSpacePoints, boardImgSpacePoints, boardSize, cameraMatrix, distortionCoeffs, rVectors, tVectors);
91 |
92 | }
93 |
94 | bool saveCalibration(string name, Mat cameraMatrix, Mat distortionCoefficients)
95 | { //saves calibration parameters to txt file, order is important for loading
96 | ofstream outStream(name);
97 | if (outStream)
98 | {
99 | uint16_t rows = cameraMatrix.rows;
100 | uint16_t columns = cameraMatrix.cols;
101 |
102 | outStream << rows << endl;
103 | outStream << columns << endl;
104 |
105 | for (int r = 0; r < rows; r++)
106 | {
107 | for (int c = 0; c < columns; c++) {
108 | double value = cameraMatrix.at(r, c);
109 | outStream << value << endl;
110 | }
111 | }
112 |
113 | rows = distortionCoefficients.rows;
114 | columns = distortionCoefficients.cols;
115 |
116 | outStream << rows << endl;
117 | outStream << columns << endl;
118 |
119 | for (int r = 0; r < rows; r++)
120 | {
121 | for (int c = 0; c < columns; c++) {
122 | double value = distortionCoefficients.at(r, c);
123 | outStream << value << endl;
124 | }
125 | }
126 |
127 | outStream.close();
128 | return true;
129 |
130 | }
131 | return false;
132 | }
133 |
134 | bool loadCalibration(string name, Mat& cameraMatrix, Mat& distortionCoefficients)
135 | {
136 | ifstream inStream(name);
137 | if (inStream)
138 | {
139 | uint16_t rows;
140 | uint16_t columns;
141 |
142 | inStream >> rows;
143 | inStream >> columns;
144 |
145 | //load camera matrix
146 | cameraMatrix = Mat(Size(columns, rows), CV_64F);
147 |
148 | for (int r = 0; r < rows; r++)
149 | {
150 | for (int c = 0; c < columns; c++)
151 | {
152 | double read = 0.0f;
153 | inStream >> read;
154 | cameraMatrix.at(r, c) = read;
155 | }
156 | }
157 |
158 | //Load Distance Coefficients
159 | inStream >> rows;
160 | inStream >> columns;
161 |
162 | distortionCoefficients = Mat::zeros(rows, columns, CV_64F);
163 |
164 | for (int r = 0; r < rows; r++)
165 | {
166 | for (int c = 0; c < columns; c++)
167 | {
168 | double read = 0.0f;
169 | inStream >> read;
170 | distortionCoefficients.at(r, c) = read;
171 | }
172 | }
173 | inStream.close();
174 | return true;
175 | }
176 |
177 | return false;
178 |
179 | }
180 |
181 | int trackPosition(const Mat& cameraMatrix, const Mat& distortionCoefficients, float markerDimensions)
182 | { //main function that mointors and detects markers
183 | Mat frame;
184 | vector markerIds;
185 | vector < vector> markerCorners, rejectedCandidates;
186 | aruco::DetectorParameters parameters;
187 |
188 | Ptr markerDictionary = aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME::DICT_4X4_50); //load correct aruco dict
189 |
190 | VideoCapture vid(0); //first webcam
191 |
192 | if (!vid.isOpened())
193 | {
194 | return -1;
195 | }
196 |
197 | namedWindow("Webcam", CV_WINDOW_AUTOSIZE);
198 |
199 | vector rotationVectors, translationVectors;
200 |
201 | while (true)
202 | {
203 | if (!vid.read(frame))
204 | break;
205 | aruco::detectMarkers(frame, markerDictionary, markerCorners, markerIds); //marker corners and ids are filled up
206 | aruco::estimatePoseSingleMarkers(markerCorners, markerDimension, cameraMatrix, distortionCoefficients, rotationVectors, translationVectors);
207 |
208 | for (int i = 0; i < markerIds.size(); i++)
209 | {
210 | aruco::drawAxis(frame, cameraMatrix, distortionCoefficients, rotationVectors[i], translationVectors[i], 0.05f);
211 |
212 | string xPos = to_string(translationVectors[i][0]);
213 | string yPos = to_string(translationVectors[i][1]);
214 | string zPos = to_string(translationVectors[i][2]);
215 | string outputCoordinates = "X: " + xPos + "\n" + " Y: " + yPos + "\n" + " Z: " + zPos;
216 | putText(frame, outputCoordinates, Point2f(30, 30), FONT_HERSHEY_PLAIN, 1, Scalar(0, 0, 255, 255));
217 |
218 | }
219 | imshow("Webcam", frame);
220 | if (waitKey(30) >= 0) break;
221 | }
222 | return 1;
223 |
224 | }
225 |
226 | void calibrationHelper(Mat& cameraMatrix, Mat& distortionCoefficients)
227 | { //here we setup camera calibration and use previous functions to help
228 | //the function looks at an image frame and draws on the corners if found, when found press space bar to save
229 | //eventually with enough saved frames we can press enter to begin calibration using the above cameraCalibration function
230 | int framesPerSecond = 30;
231 | Mat frame;
232 | Mat drawToFrame;
233 | vector savedImages;
234 | vector> markerCorners, rejectedCandidates;
235 | string textOutput = "saved";
236 | VideoCapture vid(0);
237 |
238 | if (!vid.isOpened())
239 | {
240 | return; //breaks if no video stream
241 | }
242 |
243 | namedWindow("Webcam", CV_WINDOW_AUTOSIZE);
244 |
245 | while (true)
246 | {
247 | if (!vid.read(frame)) //break if next frame not read
248 | break;
249 |
250 | vector foundPoints;
251 | bool found = false;
252 | found = findChessboardCorners(frame, chessboardSize, foundPoints, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE);
253 | frame.copyTo(drawToFrame);
254 | drawChessboardCorners(drawToFrame, chessboardSize, foundPoints, found);
255 | if (found)
256 | imshow("Webcam", drawToFrame);
257 | else
258 | imshow("Webcam", frame);
259 | char character = waitKey(1000 / framesPerSecond);
260 |
261 | switch (character)
262 | {
263 | case ' ':
264 | //save image for calibration by pressing space bar when corners found
265 | if (found) {
266 | Mat temp;
267 | frame.copyTo(temp);
268 | savedImages.push_back(temp);
269 | cout << textOutput << "\n";
270 | }
271 | break;
272 | case 13:
273 | //start calibrating by pressing enter
274 | if (savedImages.size() > 10) //only calibrates if more than 10 images are saved (aim for >30)
275 | {
276 | cameraCalibration(savedImages, chessboardSize, chessSquareDimension, cameraMatrix, distortionCoefficients);
277 | saveCalibration("CalibrationParams", cameraMatrix, distortionCoefficients);
278 | return;
279 | }
280 | break;
281 | case 27:
282 | //exit calibration by hitting escape
283 | return;
284 | break;
285 | }
286 | }
287 | }
288 |
289 | int main(int argv, char** args)
290 | { //the program first calibrates the camera, loads calibration, and begins positional tracking
291 | Mat cameraMatrix = Mat::eye(3, 3, CV_64F);
292 | Mat distortionCoefficients;
293 | string ans;
294 | cout << "Would you like to perform calibration? (Y/N)";
295 | cin >> ans;
296 |
297 | if (ans == "Y")
298 | {
299 | calibrationHelper(cameraMatrix, distortionCoefficients); //calibrates camera
300 | }
301 |
302 | loadCalibration("CalibrationParams", cameraMatrix, distortionCoefficients);
303 | trackPosition(cameraMatrix, distortionCoefficients, markerDimension);
304 |
305 | }
306 |
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/stdafx.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/stdafx.cpp
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/stdafx.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/stdafx.h
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/targetver.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/targetver.h
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Debug/CameraCa.4FE6E6C6.tlog/CL.command.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Debug/CameraCa.4FE6E6C6.tlog/CL.command.1.tlog
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Debug/CameraCa.4FE6E6C6.tlog/CL.read.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Debug/CameraCa.4FE6E6C6.tlog/CL.read.1.tlog
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Debug/CameraCa.4FE6E6C6.tlog/CL.write.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Debug/CameraCa.4FE6E6C6.tlog/CL.write.1.tlog
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Debug/CameraCa.4FE6E6C6.tlog/CameraCalibration.lastbuildstate:
--------------------------------------------------------------------------------
1 | #TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.16299.0
2 | Debug|x64|C:\Users\admin\Desktop\3DPositionalTracking\Main (C++)\Tracking\|
3 |
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Debug/CameraCa.4FE6E6C6.tlog/link.command.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Debug/CameraCa.4FE6E6C6.tlog/link.command.1.tlog
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Debug/CameraCa.4FE6E6C6.tlog/link.read.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Debug/CameraCa.4FE6E6C6.tlog/link.read.1.tlog
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Debug/CameraCa.4FE6E6C6.tlog/link.write.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Debug/CameraCa.4FE6E6C6.tlog/link.write.1.tlog
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Debug/CameraCalibration.log:
--------------------------------------------------------------------------------
1 | stdafx.cpp
2 | main.cpp
3 | CameraCalibration.vcxproj -> C:\Users\admin\Desktop\3DPositionalTracking\Main (C++)\Tracking\x64\Debug\CameraCalibration.exe
4 |
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Debug/CameraCalibration.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Debug/CameraCalibration.obj
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Debug/CameraCalibration.pch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Debug/CameraCalibration.pch
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Debug/main.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Debug/main.obj
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Debug/main.obj.enc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Debug/main.obj.enc
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Debug/stdafx.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Debug/stdafx.obj
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Debug/vc141.idb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Debug/vc141.idb
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Debug/vc141.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Debug/vc141.pdb
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Release/CameraCa.4FE6E6C6.tlog/CL.command.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Release/CameraCa.4FE6E6C6.tlog/CL.command.1.tlog
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Release/CameraCa.4FE6E6C6.tlog/CL.read.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Release/CameraCa.4FE6E6C6.tlog/CL.read.1.tlog
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Release/CameraCa.4FE6E6C6.tlog/CL.write.1.tlog:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Release/CameraCa.4FE6E6C6.tlog/CL.write.1.tlog
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Release/CameraCa.4FE6E6C6.tlog/CameraCalibration.lastbuildstate:
--------------------------------------------------------------------------------
1 | #TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.16299.0
2 | Release|x64|C:\Users\admin\Desktop\3DPositionalTracking\CameraCalibration\|
3 |
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Release/CameraCa.4FE6E6C6.tlog/unsuccessfulbuild:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Release/CameraCa.4FE6E6C6.tlog/unsuccessfulbuild
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Release/CameraCalibration.log:
--------------------------------------------------------------------------------
1 | main.cpp
2 | c:\users\admin\desktop\3dpositionaltracking\cameracalibration\cameracalibration\main.cpp(2): fatal error C1083: Cannot open include file: 'opencv2\opencv.hpp': No such file or directory
3 |
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Release/CameraCalibration.pch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Release/CameraCalibration.pch
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Release/stdafx.obj:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Release/stdafx.obj
--------------------------------------------------------------------------------
/Main (C++)/Tracking/CameraCalibration/x64/Release/vc141.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/CameraCalibration/x64/Release/vc141.pdb
--------------------------------------------------------------------------------
/Main (C++)/Tracking/x64/Debug/CameraCalibration.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/x64/Debug/CameraCalibration.exe
--------------------------------------------------------------------------------
/Main (C++)/Tracking/x64/Debug/CameraCalibration.ilk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/x64/Debug/CameraCalibration.ilk
--------------------------------------------------------------------------------
/Main (C++)/Tracking/x64/Debug/CameraCalibration.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Main (C++)/Tracking/x64/Debug/CameraCalibration.pdb
--------------------------------------------------------------------------------
/Python Scripts/Helper/ar_markers_generate.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | from __future__ import print_function
4 | import argparse
5 |
6 | try:
7 | from cv2 import imwrite
8 | from ar_markers.marker import HammingMarker
9 | from ar_markers import __version__
10 | except ImportError:
11 | raise Exception('Error: OpenCv is not installed')
12 |
13 |
14 | def handleArgs():
15 | parser = argparse.ArgumentParser(description='Generate ar markers')
16 | # parser.add_argument('-v', '--version', help='print version number', version=__version__)
17 | parser.add_argument('-g', '--generate', help='generate n random markers', type=int)
18 | parser.add_argument('-i', '--id', help='generate a marker with a specific id', type=int)
19 | parser.add_argument('-p', '--path', help='path to write ar markers to, default is current directory', default='.')
20 |
21 | args = vars(parser.parse_args())
22 | return args
23 |
24 |
25 | if __name__ == '__main__':
26 | args = handleArgs()
27 | path = args['path'] + '/marker_{}.png'
28 |
29 | print(args)
30 |
31 | if args['generate']:
32 | for i in range(args['generate']):
33 | marker = HammingMarker.generate()
34 | imwrite(path.format(marker.id), marker.generate_image())
35 | print("Generated Marker with ID {}".format(marker.id))
36 | elif args['id']:
37 | marker = HammingMarker(id=args['id'])
38 | imwrite(path.format(marker.id), marker.generate_image())
39 | print("Generated Marker with ID {}".format(marker.id))
40 | else:
41 | marker = HammingMarker.generate()
42 | imwrite(path.format(marker.id), marker.generate_image())
43 | print("Generated Marker with ID {}".format(marker.id))
44 | print('Done!')
45 |
--------------------------------------------------------------------------------
/Python Scripts/Helper/ar_markers_scan.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | from __future__ import print_function
4 |
5 | try:
6 | import cv2
7 | from ar_markers import detect_markers
8 | except ImportError:
9 | raise Exception('Error: OpenCv is not installed')
10 |
11 |
12 | if __name__ == '__main__':
13 | print('Press "q" to quit')
14 | capture = cv2.VideoCapture(0)
15 |
16 | if capture.isOpened(): # try to get the first frame
17 | frame_captured, frame = capture.read()
18 | else:
19 | frame_captured = False
20 | while frame_captured:
21 | markers = detect_markers(frame)
22 | for marker in markers:
23 | marker.highlite_marker(frame)
24 | cv2.imshow('Test Frame', frame)
25 | if cv2.waitKey(1) & 0xFF == ord('q'):
26 | break
27 | frame_captured, frame = capture.read()
28 |
29 | # When everything done, release the capture
30 | capture.release()
31 | cv2.destroyAllWindows()
32 |
--------------------------------------------------------------------------------
/Python Scripts/Helper/camTest.py:
--------------------------------------------------------------------------------
1 | import numpy
2 | import cv2
3 | import argparse
4 | import imutils
5 |
6 | video = cv2.VideoCapture(0)
7 |
8 | if (video.isOpened() == False):
9 | print("Error opening videstream or file")
10 |
11 | while (video.isOpened()):
12 | ok, frame = video.read()
13 | if ok:
14 | cv2.imshow("Frame", frame)
15 | if cv2.waitKey(25) & 0xFF == ord('q'):
16 | break
17 | else:
18 | print ("something went wrong")
19 | break
20 |
21 | video.release()
22 | cv2.destroyAllWindows()
23 |
--------------------------------------------------------------------------------
/Python Scripts/Helper/marker_only_tracking.py:
--------------------------------------------------------------------------------
1 |
2 | from __future__ import print_function
3 | import cv2
4 | from ar_markers import detect_markers
5 |
6 |
7 | if __name__ == '__main__':
8 | print('Press "q" to quit')
9 | capture = cv2.VideoCapture(0)
10 |
11 | if capture.isOpened(): # try to get the first frame
12 | frame_captured, frame = capture.read()
13 | else:
14 | frame_captured = False
15 |
16 | while frame_captured:
17 | markers = detect_markers(frame)
18 | for marker in markers:
19 | marker.highlite_marker(frame)
20 | cv2.imshow('Test Frame', frame)
21 | if cv2.waitKey(1) & 0xFF == ord('q'):
22 | break
23 | frame_captured, frame = capture.read()
24 |
25 | # When everything done, release the capture
26 | capture.release()
27 | cv2.destroyAllWindows()
28 |
--------------------------------------------------------------------------------
/Python Scripts/Helper/marker_tracking_opencv.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import cv2
3 | import cv2.aruco as aruco
4 | import sys
5 |
6 | video = cv2.VideoCapture(0)
7 |
8 | #Error checking
9 | if not video.isOpened():
10 | print ("ERROR: COULD NOT OPEN VIDEO ")
11 | sys.exit()
12 |
13 | aruco_dict = aruco.getPredefinedDictionary(aruco.DICT_4X4_50)
14 |
15 | while(True):
16 | #read frame
17 | ok, frame = video.read()
18 | if not ok:
19 | print ("ERROR: COULD NOT READ FIRST FRAME FROM FILE")
20 | sys.exit()
21 |
22 | #frame operations
23 | gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
24 | parameters = aruco.DetectorParameters_create()
25 |
26 | #list ids and respective corners
27 | corners, ids, rejectedImgPoints = aruco.detectMarkers(gray, aruco_dict, parameters=parameters)
28 | frame = aruco.drawDetectedMarkers(frame, corners, borderColor=(255,0,0))
29 | frame = aruco.drawDetectedMarkers(frame, rejectedImgPoints, borderColor=(0,0,255))
30 |
31 | cv2.imshow('frame', frame)
32 | if cv2.waitKey(1) & 0xFF == ord('q'):
33 | break
34 |
35 | video.release()
36 | cv2.destroyAllWindows()
37 |
--------------------------------------------------------------------------------
/Python Scripts/caputils.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import cv2
3 | import cv2.aruco as aruco
4 | import sys
5 | import argparse
6 | from ar_markers import detect_markers
7 | from scipy.spatial import distance as dist
8 |
9 | def generateMarkers():
10 | aruco_dict = aruco.Dictionary_get(aruco.DICT_6X6_250)
11 | print(aruco_dict)
12 | # second parameter is id number
13 | # last parameter is total image size
14 | img = aruco.drawMarker(aruco_dict, 2, 700)
15 | cv2.imwrite("../Samples/Pictures/Markers/marker.jpg", img)
16 |
17 | cv2.imshow('frame',img)
18 | cv2.waitKey(0)
19 | cv2.destroyAllWindows()
20 |
21 |
22 | def calcValues(refCoords, objCoords):
23 |
24 | """
25 | Take two objects and their coordinates in the form of a list or tuple
26 | Each object is defined by a bounding rectangle
27 | returns:
28 | - euclidean distance between two in pixels
29 | - center point of each object
30 | - ppm ratio current
31 | """
32 | a,b = refCoords
33 | c,d = objCoords
34 |
35 | centerRef = midpoint(a,b)
36 | centerObj = midpoint(c,d)
37 |
38 | euclid_dist = dist.euclidean()
39 |
40 | ppm = dist.euclidean()
41 | return euclid_dist, ppm
42 |
--------------------------------------------------------------------------------
/Python Scripts/tracking.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import sys
3 | import argparse
4 | from ar_markers import detect_markers
5 |
6 | """
7 | Provides tracking through 2 mechanisms
8 | -Tracker based with specified selectROI --> move towards using a CONVNET?
9 | -Marker baed mech --> highlights current marker position
10 | """
11 | #save which opencv version is being used
12 | (major_ver, minor_ver, subminor_ver) = (cv2.__version__).split(".")
13 |
14 | #this control flow ensures this file is being called not imported
15 | if __name__ == '__main__':
16 | #argument parsing for main program
17 | ap = argparse.ArgumentParser()
18 | ap.add_argument("-v", "--video", help="path to video from current directory")
19 | args = vars(ap.parse_args())
20 |
21 | #tracker setup by default uses KCF
22 | tracker_types = ['BOOSTING', 'MIL','KCF', 'TLD', 'MEDIANFLOW', 'GOTURN']
23 | tracker_type = tracker_types[1]
24 |
25 | #ensure it works for different versions
26 | #and initialize tracker type
27 | if int(minor_ver) < 3:
28 | tracker = cv2.Tracker_create(tracker_type)
29 | else:
30 | if tracker_type == 'BOOSTING':
31 | tracker = cv2.TrackerBoosting_create()
32 | if tracker_type == 'MIL':
33 | tracker = cv2.TrackerMIL_create()
34 | if tracker_type == 'KCF':
35 | tracker = cv2.TrackerKCF_create()
36 | if tracker_type == 'TLD':
37 | tracker = cv2.TrackerTLD_create()
38 | if tracker_type == 'MEDIANFLOW':
39 | tracker = cv2.TrackerMedianFlow_create()
40 | if tracker_type == 'GOTURN':
41 | tracker = cv2.TrackerGOTURN_create()
42 |
43 | #activate webcam or livestream
44 | if not args.get("video", False):
45 | video = cv2.VideoCapture(0)
46 | else:
47 | video = cv2.VideoCapture(args["video"])
48 |
49 | #exit if video not read
50 | if not video.isOpened():
51 | print ("ERROR: COULD NOT OPEN VIDEO FILE")
52 | sys.exit()
53 |
54 | #read frame one
55 | ok, frame = video.read()
56 | if not ok:
57 | print ("ERROR: COULD NOT READ FIRST FRAME FROM FILE")
58 | sys.exit()
59 |
60 | #init bounding box
61 | bbox = (287,23,86,320)
62 |
63 | #different initla bounding box done by specifying rectangle of interest
64 | #bbox = cv2.selectROI(frame,False)
65 | #print bbox
66 |
67 | #init tracker
68 | ok = tracker.init(frame,bbox)
69 |
70 | #begin looping over frames
71 | while True:
72 | #next frame, make sure its there or break
73 | ok, frame = video.read()
74 | if not ok:
75 | print ("ERROR: COULD NOT READ NEXT FRAME")
76 | break
77 |
78 | #start timer
79 | timer = cv2.getTickCount()
80 |
81 | ##marker detection
82 | markers = detect_markers(frame)
83 | for marker in markers:
84 | marker.highlite_marker(frame)
85 |
86 | #update tracker and bbox to current frame
87 | ok, bbox = tracker.update(frame)
88 |
89 | #calc fps [frames/change in time] == fps
90 | fps = cv2.getTickFrequency() / (cv2.getTickCount() - timer)
91 |
92 | #draw bbox if tracker updated else indicate failure
93 | if ok:
94 | p1 = (int(bbox[0]), int(bbox[1]))
95 | p2 = (int(bbox[0] + bbox[2]), int(bbox[1] + bbox[3]))
96 | cv2.rectangle(frame, p1, p2, (255,0,0), 2, 1)
97 | else:
98 | cv2.putText(frame, "Tracking failure detected", (100,80), cv2.FONT_HERSHEY_SIMPLEX, 0.75,(0,0,255),2)
99 |
100 | #display tracker type, fps, and resultant frames
101 | cv2.putText(frame, tracker_type + " Tracker", (100,20), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50,170,50),2);
102 | cv2.putText(frame, "FPS : " + str(int(fps)), (100,50), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50,170,50), 2);
103 | cv2.imshow("Tracking", frame)
104 |
105 | # Exit if ESC pressed
106 | k = cv2.waitKey(1) & 0xff
107 | if k == 27 : break
108 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 3D Positional Tracking with Markers
2 |
3 | Program to calibrate camera and track cartesian distances to markers, with camera as the origin. Greatest accuracy achieved was within 1mm. The intended purpose was for use as a tracking module in an arthroscopic surgical training station.
4 |
5 |
6 | Camera Calibration
7 | 
8 |
9 | Tracking Sample
10 | 
11 |
12 | Great thanks to George Lecakes for amazing series on marker tracking with OpenCV. Can be found here for those interested: https://www.youtube.com/watch?v=CfymgQwB_vE
13 |
--------------------------------------------------------------------------------
/Result Pictures/10 cm left 1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Result Pictures/10 cm left 1.PNG
--------------------------------------------------------------------------------
/Result Pictures/10 cm right 1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Result Pictures/10 cm right 1.PNG
--------------------------------------------------------------------------------
/Result Pictures/10 cm right 2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Result Pictures/10 cm right 2.PNG
--------------------------------------------------------------------------------
/Result Pictures/10cm left 1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Result Pictures/10cm left 1.PNG
--------------------------------------------------------------------------------
/Result Pictures/4cm high 2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Result Pictures/4cm high 2.PNG
--------------------------------------------------------------------------------
/Result Pictures/4cm high.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Result Pictures/4cm high.PNG
--------------------------------------------------------------------------------
/Result Pictures/8cm high 2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Result Pictures/8cm high 2.PNG
--------------------------------------------------------------------------------
/Result Pictures/8cm high.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Result Pictures/8cm high.PNG
--------------------------------------------------------------------------------
/Result Pictures/90degrees 14 cm away 2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Result Pictures/90degrees 14 cm away 2.PNG
--------------------------------------------------------------------------------
/Result Pictures/90degrees 14 cm away.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Result Pictures/90degrees 14 cm away.PNG
--------------------------------------------------------------------------------
/Result Pictures/90degrees 30 cm away 2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Result Pictures/90degrees 30 cm away 2.PNG
--------------------------------------------------------------------------------
/Result Pictures/90degrees 30 cm away.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Result Pictures/90degrees 30 cm away.PNG
--------------------------------------------------------------------------------
/Result Pictures/90degrees 50 cm away 2.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Result Pictures/90degrees 50 cm away 2.PNG
--------------------------------------------------------------------------------
/Result Pictures/90degrees 50 cm away.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Result Pictures/90degrees 50 cm away.PNG
--------------------------------------------------------------------------------
/Result Pictures/calibration.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Result Pictures/calibration.PNG
--------------------------------------------------------------------------------
/Samples/Pictures/Markers/marker.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Samples/Pictures/Markers/marker.jpg
--------------------------------------------------------------------------------
/Samples/Pictures/box_sample.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Samples/Pictures/box_sample.jpg
--------------------------------------------------------------------------------
/Samples/Pictures/markerdoc.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Samples/Pictures/markerdoc.docx
--------------------------------------------------------------------------------
/Samples/Pictures/markerdoc.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RaedShabbir/3DPositionalTracking/66a77423350c15566451460af8a68df48a6495bc/Samples/Pictures/markerdoc.pdf
--------------------------------------------------------------------------------
/environment.yml:
--------------------------------------------------------------------------------
1 | name: capstone
2 | channels:
3 | - anaconda-fusion
4 | - defaults
5 | dependencies:
6 | - alabaster=0.7.10=py27h2cab13d_0
7 | - anaconda-client=1.6.14=py27_0
8 | - anaconda=custom=py27h689e5c3_0
9 | - anaconda-project=0.8.2=py27he89e3ca_0
10 | - asn1crypto=0.24.0=py27_0
11 | - astroid=1.6.1=py27_0
12 | - astropy=2.0.3=py27h0c8e037_0
13 | - attrs=17.4.0=py27_0
14 | - babel=2.5.3=py27_0
15 | - backports=1.0=py27h6492d98_1
16 | - backports.functools_lru_cache=1.4=py27h9586e20_1
17 | - backports.shutil_get_terminal_size=1.0.0=py27h1657125_2
18 | - backports.shutil_which=3.5.1=py27_2
19 | - backports_abc=0.5=py27h0ec6b72_0
20 | - beautifulsoup4=4.6.0=py27hc287451_1
21 | - bitarray=0.8.1=py27h0c8e037_1
22 | - bkcharts=0.2=py27h92b6de3_0
23 | - blaze=0.11.3=py27h97e5449_0
24 | - bleach=2.1.2=py27_0
25 | - bokeh=0.12.13=py27h5a33001_0
26 | - boto=2.48.0=py27h1ccb131_1
27 | - bottleneck=1.2.1=py27hde90680_0
28 | - bzip2=1.0.6=h8a7aa22_4
29 | - ca-certificates=2017.08.26=h94faf87_0
30 | - cdecimal=2.3=py27h0c8e037_3
31 | - certifi=2018.1.18=py27_0
32 | - cffi=1.11.4=py27h0c8e037_0
33 | - chardet=3.0.4=py27h56c3b73_1
34 | - click=6.7=py27hb6defca_0
35 | - cloudpickle=0.5.2=py27_1
36 | - clyent=1.2.2=py27h4424948_1
37 | - colorama=0.3.9=py27hdfe4ae1_0
38 | - comtypes=1.1.4=py27_0
39 | - configparser=3.5.0=py27h2fa79a8_0
40 | - console_shortcut=0.1.1=h6bb2dd7_3
41 | - contextlib2=0.5.5=py27h42efda5_0
42 | - cryptography=2.1.4=py27h0628b04_0
43 | - curl=7.58.0=h7a46e7a_0
44 | - cycler=0.10.0=py27h59acbbf_0
45 | - cython=0.27.3=py27h566c365_0
46 | - cytoolz=0.9.0=py27h0c8e037_0
47 | - dask=0.16.1=py27_0
48 | - dask-core=0.16.1=py27_0
49 | - datashape=0.5.4=py27h3d6e61b_0
50 | - decorator=4.2.1=py27_0
51 | - distributed=1.20.2=py27_0
52 | - docutils=0.14=py27h8652d09_0
53 | - entrypoints=0.2.3=py27h0271f2b_2
54 | - enum34=1.1.6=py27h2aa175b_1
55 | - et_xmlfile=1.0.1=py27h1de5d23_0
56 | - fastcache=1.0.2=py27h0c8e037_2
57 | - filelock=2.0.13=py27h49e51d3_0
58 | - flask=0.12.2=py27h30d9212_0
59 | - flask-cors=3.0.3=py27h4926b05_0
60 | - freetype=2.8=hea645e0_1
61 | - funcsigs=1.0.2=py27h8885ae1_0
62 | - functools32=3.2.3.2=py27h0cdbcdb_1
63 | - futures=3.2.0=py27h8b2aecd_0
64 | - get_terminal_size=1.0.0=h38e98db_0
65 | - gevent=1.2.2=py27h1842022_0
66 | - glob2=0.6=py27hd4eee8c_0
67 | - greenlet=0.4.12=py27h32400d3_0
68 | - grin=1.2.1=py27_4
69 | - h5py=2.7.1=py27h2dd4c20_0
70 | - hdf5=1.10.1=h79de857_2
71 | - heapdict=1.0.0=py27_2
72 | - html5lib=1.0.1=py27h5a33001_0
73 | - icc_rt=2017.0.4=h97af966_0
74 | - icu=58.2=h2aa20d9_1
75 | - idna=2.6=py27h1ea29d3_1
76 | - imageio=2.2.0=py27h283db88_0
77 | - imagesize=0.7.1=py27h1482bd8_0
78 | - intel-openmp=2018.0.0=hd92c6cd_8
79 | - ipaddress=1.0.19=py27_0
80 | - ipykernel=4.8.0=py27_0
81 | - ipython=5.4.1=py27_2
82 | - ipython_genutils=0.2.0=py27hbe997df_0
83 | - ipywidgets=7.1.1=py27_0
84 | - isort=4.2.15=py27hdc949c3_0
85 | - itsdangerous=0.24=py27hcf63135_1
86 | - jdcal=1.3=py27h8c72977_0
87 | - jedi=0.11.1=py27_0
88 | - jinja2=2.10=py27hba1794b_0
89 | - jpeg=9b=ha175dff_2
90 | - jsonschema=2.6.0=py27haaf3834_0
91 | - jupyter=1.0.0=py27_4
92 | - jupyter_client=5.2.2=py27_0
93 | - jupyter_console=5.2.0=py27h6ed736b_1
94 | - jupyter_core=4.4.0=py27h1619e65_0
95 | - jupyterlab=0.31.4=py27_0
96 | - jupyterlab_launcher=0.10.2=py27_0
97 | - lazy-object-proxy=1.3.1=py27ha5c8080_0
98 | - libcurl=7.58.0=h7a46e7a_0
99 | - libiconv=1.15=hda2e4ec_7
100 | - libpng=1.6.34=h325896a_0
101 | - libssh2=1.8.0=h77a7533_4
102 | - libtiff=4.0.9=hafacce9_0
103 | - libxml2=2.9.7=h325896a_0
104 | - libxslt=1.1.32=h89dfad8_0
105 | - llvmlite=0.21.0=py27h831ec56_0
106 | - locket=0.2.0=py27h1ca288a_1
107 | - lxml=4.1.1=py27h31b8cb8_1
108 | - lzo=2.10=h0bb7fe3_2
109 | - markupsafe=1.0=py27h9d4480d_1
110 | - matplotlib=2.1.2=py27ha51faf0_0
111 | - mccabe=0.6.1=py27hde0bf6e_1
112 | - menuinst=1.4.11=py27h0c8e037_0
113 | - mistune=0.8.3=py27_0
114 | - mkl=2018.0.1=h2108138_4
115 | - mkl-service=1.1.2=py27h3c6b6b0_4
116 | - mpmath=1.0.0=py27h0d59bc2_2
117 | - msgpack-python=0.5.1=py27hdc96acc_0
118 | - multipledispatch=0.4.9=py27h8ebb51e_0
119 | - nbconvert=5.3.1=py27h7a573cf_0
120 | - nbformat=4.4.0=py27hf49b375_0
121 | - networkx=2.1=py27_0
122 | - nltk=3.2.5=py27h88af825_0
123 | - nose=1.3.7=py27h84c72c6_2
124 | - notebook=5.4.0=py27_0
125 | - numba=0.36.2=np114py27h719e94c_0
126 | - numexpr=2.6.4=py27h20dc147_0
127 | - numpy=1.14.2=py27h0bb1d87_0
128 | - numpydoc=0.7.0=py27hf7b062b_0
129 | - odo=0.5.1=py27h64810b2_0
130 | - olefile=0.45.1=py27_0
131 | - openpyxl=2.4.10=py27_0
132 | - openssl=1.0.2n=hc64555f_0
133 | - packaging=16.8=py27hae1a450_1
134 | - pandas=0.22.0=py27hc56fc5f_0
135 | - pandoc=1.19.2.1=hb2460c7_1
136 | - pandocfilters=1.4.2=py27h76461d3_1
137 | - parso=0.1.1=py27hd69ea77_0
138 | - partd=0.3.8=py27h1e0692f_0
139 | - path.py=10.5=py27he482d56_0
140 | - pathlib2=2.3.0=py27h0ae272f_0
141 | - patsy=0.5.0=py27_0
142 | - pep8=1.7.1=py27_0
143 | - pickleshare=0.7.4=py27hb5f6335_0
144 | - pillow=5.0.0=py27h901f87c_0
145 | - pip=9.0.1=py27hdaa76b4_4
146 | - pkginfo=1.4.1=py27h6ce81e3_1
147 | - pluggy=0.6.0=py27h89dc50b_0
148 | - ply=3.10=py27h5fb8a85_0
149 | - prompt_toolkit=1.0.15=py27h3a8ec6a_0
150 | - psutil=5.4.3=py27h0c8e037_0
151 | - py=1.5.2=py27ha24bda0_0
152 | - pycodestyle=2.3.1=py27h24cd5d9_0
153 | - pycosat=0.6.3=py27hcd410c5_0
154 | - pycparser=2.18=py27hb43d16c_1
155 | - pycrypto=2.6.1=py27h0c8e037_7
156 | - pycurl=7.43.0.1=py27hc64555f_0
157 | - pyflakes=1.6.0=py27h34e7826_0
158 | - pygments=2.2.0=py27ha50f84f_0
159 | - pylint=1.8.2=py27_0
160 | - pyodbc=4.0.22=py27hc56fc5f_0
161 | - pyopenssl=17.5.0=py27h59156d7_0
162 | - pyparsing=2.2.0=py27hc7d9fa6_1
163 | - pyqt=5.6.0=py27h224ed30_5
164 | - pysocks=1.6.7=py27h59bdd1e_1
165 | - pytables=3.4.2=py27h583b7c0_2
166 | - pytest=3.3.2=py27_0
167 | - python=2.7.14=h8c3f1cb_23
168 | - python-dateutil=2.6.1=py27hbdcc174_1
169 | - pytz=2017.3=py27hca431c1_0
170 | - pywavelets=0.5.2=py27h0dc3f48_0
171 | - pywin32=222=py27h0c8e037_0
172 | - pywinpty=0.5=py27hc56fc5f_1
173 | - pyyaml=3.12=py27ha287073_1
174 | - pyzmq=16.0.3=py27he883654_0
175 | - qt=5.6.2=vc9hc26998b_12
176 | - qtawesome=0.4.4=py27h766b13d_0
177 | - qtconsole=4.3.1=py27h77d40ac_0
178 | - qtpy=1.3.1=py27h1ff2b4b_0
179 | - requests=2.18.4=py27h3159eba_1
180 | - rope=0.10.7=py27hb65afb6_0
181 | - ruamel_yaml=0.15.35=py27h0c8e037_1
182 | - scandir=1.6=py27h518bda0_0
183 | - scikit-image=0.13.1=py27h0c8e037_1
184 | - scikit-learn=0.19.1=py27he00e316_0
185 | - scipy=1.0.0=py27h7cd1477_0
186 | - seaborn=0.8.1=py27hab56d54_0
187 | - send2trash=1.4.2=py27_0
188 | - setuptools=38.4.0=py27_0
189 | - simplegeneric=0.8.1=py27_2
190 | - singledispatch=3.4.0.3=py27h3f9d112_0
191 | - sip=4.18.1=py27h5ec1c1a_2
192 | - six=1.11.0=py27ha5e1701_1
193 | - snowballstemmer=1.2.1=py27h28d3bf7_0
194 | - sortedcollections=0.5.3=py27h21b938c_0
195 | - sortedcontainers=1.5.9=py27_0
196 | - sphinx=1.6.6=py27_0
197 | - sphinxcontrib=1.0=py27h0e2fb95_1
198 | - sphinxcontrib-websupport=1.0.1=py27h0d0f901_1
199 | - spyder=3.2.6=py27_0
200 | - sqlalchemy=1.2.1=py27h0c8e037_0
201 | - sqlite=3.22.0=h8b3e59e_0
202 | - ssl_match_hostname=3.5.0.1=py27hea8a0f4_2
203 | - statsmodels=0.8.0=py27hc77c1fc_0
204 | - subprocess32=3.2.7=py27hcc576e2_0
205 | - sympy=1.1.1=py27hde44fae_0
206 | - tblib=1.3.2=py27h8ae915c_0
207 | - terminado=0.8.1=py27_1
208 | - testpath=0.3.1=py27h1cd488d_0
209 | - tk=8.6.7=h144d9c4_3
210 | - toolz=0.9.0=py27_0
211 | - tornado=4.5.3=py27_0
212 | - traitlets=4.3.2=py27h1b1b3a5_0
213 | - typing=3.6.2=py27h9197bb0_0
214 | - unicodecsv=0.14.1=py27h0bf7bb0_0
215 | - urllib3=1.22=py27hb9f5a07_0
216 | - vc=9=h7299396_1
217 | - vs2008_runtime=9.00.30729.1=hfaea7d5_1
218 | - vs2015_runtime=14.0.25123=3
219 | - wcwidth=0.1.7=py27hb1a0d82_0
220 | - webencodings=0.5.1=py27h4e224a2_1
221 | - werkzeug=0.14.1=py27_0
222 | - wheel=0.30.0=py27ha643586_1
223 | - widgetsnbextension=3.1.0=py27_0
224 | - win_inet_pton=1.0.1=py27hf41312a_1
225 | - win_unicode_console=0.5=py27hc037021_0
226 | - wincertstore=0.2=py27hf04cefb_0
227 | - winpty=0.4.3=4
228 | - wrapt=1.10.11=py27hcd2b27d_0
229 | - xlrd=1.1.0=py27h2b87a7f_1
230 | - xlsxwriter=1.0.2=py27h5ed79b1_0
231 | - xlwings=0.11.5=py27_0
232 | - xlwt=1.3.0=py27h2271735_0
233 | - yaml=0.1.7=h3e6d941_2
234 | - zict=0.1.3=py27h0171463_0
235 | - zlib=1.2.11=hbc2faf4_2
236 | prefix: C:\Users\Raed\Anaconda3\envs\capstone
237 |
238 |
--------------------------------------------------------------------------------
/temp.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "opencv2\opencv.hpp"
3 | #include "opencv2\core.hpp"
4 | #include "opencv2\imgproc.hpp"
5 | #include "opencv2\highgui.hpp"
6 | #include "opencv2\aruco.hpp"
7 | #include "opencv2\calib3d.hpp"
8 |
9 | #include
10 | #include
11 | #include
12 |
13 |
14 | using namespace cv;
15 | using namespace std;
16 |
17 | //enter key values in meters
18 | const float calibrationSquareDimension = 0.0245f;
19 | const float arucoSquareDimension = 0.5f;
20 | const Size chessboardDimensions = Size(6, 9);
21 |
22 | void createArucoMarkers()
23 | {
24 | Mat outputMarker;
25 | //setup the predefined aruco marker dictionary (50 markers inside)
26 | Ptr markerDictionary = aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME::DICT_4X4_50);
27 |
28 | //iterate and write markers to project directory
29 | for (int i = 0; i < 8; i++)
30 | {
31 | aruco::drawMarker(markerDictionary, i, 500, outputMarker, 1);
32 | ostringstream convert; //must append i to marker name
33 | string imageName = "4x4Marker_";
34 | convert << imageName << i << ".jpg";
35 | imwrite(convert.str(), outputMarker);
36 |
37 | }
38 | }
39 |
40 | void createKnownBoardPositions(Size, boardSize, float squareEdgeLength, vector& corners)
41 | {
42 | for (int i = 0; i < boardSize.height; i++)
43 | {
44 | for (int j = 0; j < boardSize.width; j++)
45 | {
46 | corners.push_back(Point3f(j * squareEdgeLength, i*squareEdgeLength, 0.0f)); //note z is zero since we have a flat plane
47 | }
48 | }
49 |
50 |
51 | }
52 |
53 | void getChessboardCorners(vector images, vector>&allFoundCorners, bool showResults = false)
54 | { //function for calibrating based on images only
55 | //so after receiving a vector full of images, we want to extract the corners
56 | for (vector::iterator iter = images.begin(); iter != images.end(); iter++) {
57 | vector pointBuf;
58 | bool found = findChessboardCorners(*iter, Size(9,6), pointBuf, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE);
59 | if (found)
60 | {
61 | allFoundCorners.push_back(pointBuf);
62 | }
63 | if (showResults)
64 | {
65 | drawChessboardCorners(*iter, Size(9, 6), pointBuf, found);
66 | imshow("Corner Finder", *iter);
67 | waitKey(0);
68 | }
69 | }
70 | }
71 |
72 | int main(int argv, char** args)
73 | {
74 | createArucoMarkers();
75 | //only run this once to generate the markers
76 | int framesPerSecond = 20;
77 | Mat frame;
78 | Mat drawToFrame;
79 | Mat cmeraMatrix = Mat::eye(3, 3, CV_64F);
80 | Mat distanceCoefficients;
81 | vector savedImages; //can save good calibrations
82 | vector> markerCorners, rejectedCandidates;
83 |
84 | VideoCapture vid(0);
85 |
86 | if (!vid.isOpened())
87 | {
88 | return;
89 | }
90 |
91 | namedWindow("Webcam", CV_WINDOW_AUTOSIZE);
92 |
93 | while (true)
94 | {
95 | if (!vid.read(frame)) //break if next frame not read
96 | break;
97 |
98 | vector foundPoints;
99 | bool found = false;
100 | found = findChessboardCorners(frame, chessboardDimensions, )
101 |
102 |
103 |
104 | }
105 |
106 | }
107 |
--------------------------------------------------------------------------------