artoolkit_secret
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | artoolkit_secret [2016/11/16 20:03] (current) – created dwallace | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== ARToolkit ====== | ||
+ | **Author:** Dylan Wallace Email: < | ||
+ | \\ | ||
+ | **Date:** Last modified on 08/28/16 | ||
+ | \\ | ||
+ | **Keywords: | ||
+ | \\ | ||
+ | |||
+ | {{ : | ||
+ | \\ | ||
+ | The photo above depicts coordinate tracking of a marker with the ARToolkit SDK, which allows you to track the relative position of something with a marker attached to it. The big picture problem is tracking movement for computer vision and navigation applications. Solving this partially or completely is important because it allows for objects to be quickly located, and used in programs for various applications. This tutorial shows you how to install, setup, and use the ARToolkit, and takes approximately 3 hours to complete. | ||
+ | \\ | ||
+ | ===== Motivation and Audience ===== | ||
+ | |||
+ | This tutorial' | ||
+ | |||
+ | <fc blue> | ||
+ | * Know how to use basic Linux and Windows commands | ||
+ | \\ | ||
+ | * Perhaps also know how to program in C/Cpp, especially with Visual Studio. | ||
+ | \\ | ||
+ | * Perhaps additional background needed may include experience with other frameworks such as OpenCV or OpenGL. | ||
+ | \\ | ||
+ | * This tutorial may also attract readers who are interested in path planning, computer vision, NXT applications, | ||
+ | </fc> | ||
+ | \\ \\ | ||
+ | **// | ||
+ | \\ | ||
+ | The rest of this tutorial is presented as follows: | ||
+ | * [[nxt_ar_toolkit# | ||
+ | * [[nxt_ar_toolkit# | ||
+ | * Final Words | ||
+ | ===== Installation and Setup ===== | ||
+ | |||
+ | ==== Step 1: Download ==== | ||
+ | |||
+ | Start by downloading the [[https:// | ||
+ | |||
+ | ==== Step 2: Install ==== | ||
+ | |||
+ | Once you have downloaded the necessary package for your operating system, install the ARToolkit SDK using these [[https:// | ||
+ | |||
+ | ==== Step 3: Obtain Missing DLLs ==== | ||
+ | |||
+ | If you are running on a newer Windows installation, | ||
+ | |||
+ | ===== Using the ARToolkit ===== | ||
+ | |||
+ | ==== Step 1: Printing markers/ | ||
+ | |||
+ | The most important part of running any examples or other programs for ARToolkit is making sure your markers or fiducials are printed properly. For the simple examples from ARToolkit, we will use the Hiro pattern, found in C:\Program Files (x86)\ARToolKit5\doc\patterns. Optionally, {{: | ||
+ | |||
+ | ==== Step 2: Running the Example ==== | ||
+ | |||
+ | Once you have printed your marker, you are now able to run the most basic example that ARToolkit provides for testing the SDK. Go into your ARToolkit5 folder, and run the simpleLite program located in the bin folder. Accept the default values that popup for the video configuration, | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | When you move the marker along your surface, or even into the air, the colored cube should follow the marker. If not, then you may need to calibrate your camera parameters. | ||
+ | |||
+ | ==== Optional: Step 3: Calibrate Camera ==== | ||
+ | |||
+ | If the marker is not recognized by the ARToolkit simpleLite program, or if the marker tracking is not smooth, you may want to calibrate your camera parameters. Before calibrating your camera, you will need to print out the calibration chessboard. This should be located with the other ARToolkit patterns (in the doc folder of the ARToolkit5 directory), but i have also linked it {{: | ||
+ | |||
+ | Open the bin folder inside the ARToolkit5 directory, and run the calib_camera.exe file as administrator. Select the defaults for the camera configuration before the program runs. Once your video is streaming, use the chessboard pattern glued onto a flat surface, to calibrate the camera. The video will look for all the corners on the chessboard, and these will turn red when it is ready to use these for calibration. The output should look something like this when the chessboard is in full view: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | Press space bar to capture the frame once all the corners have turned red. Keep your camera in a fixed position, and move the board with the pattern around your area. Try multiple angles and locations of the board, in order to get a variety of test data. Once you have captured 10 frames, the program will ask you to save the camera_para.dat file. Just press enter and the file will be saved into the bin folder. The last thing that you need to do is to replace this camera_para.dat file with the camera_para.dat file located in the Data folder of the bin directory. | ||
+ | |||
+ | Now run the simpleLite program again to see if these new parameters will help with tracking issues. If you are still having issues with tracking or recognizing markers, refer to the next step for debugging these issues. | ||
+ | |||
+ | ==== Optional: Step 4: Debugging Marker Recognition ==== | ||
+ | |||
+ | If even after calibrating your camera, you are still having marker recognition or tracking problems, then you may need to run the check_id.exe program provided in the ARToolkit5 directory, bin folder. This program will run through the different steps of the ARToolkit marker recognition process, and will help you figure out where your program is failing. You can use any of the square markers for this, but i recommend using the Hiro marker because it has the best contrast. When you start this program, your output should look something like this: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | The marker will be outlined in a different color depending on the results of each step of the recognition process. Below I will explain the different cases you can have, and what to do to fix them. | ||
+ | |||
+ | **Red Outline:** This is the ideal scenario. This means that the program is able to detect the marker and full track its movement. | ||
+ | |||
+ | **Light Blue Outline:** This means that the pattern extraction has failed. This can be caused by uneven lines in printing, or scaling issues with the pattern onto the paper. Try fixing this by playing with the settings on your printer, or changing the layout/ | ||
+ | |||
+ | **Blue Outline:** This is a generic matching error. Often when this comes up, it can be similar problems to the light blue outline. When this code comes up, try printing a new marker, or recalibrating your camera. | ||
+ | |||
+ | **Brown Outline:** This is the most common error to get with the pattern recognition. This means that the contrast between the black and the white in the marker is not high enough, and therefore the marker is not properly processed. This can be fixed by adjusting printer settings, print quality settings on your computer, or by replacing ink/toner cartridges. | ||
+ | |||
+ | **Purple/ | ||
+ | |||
+ | **Green Outline:** This means that the cutoff value for confidence matching was not reached by the program. Basically this means that the computer can vaguely recognize the marker as a marker, but its not completely sure if it actually is so it doesn' | ||
+ | |||
+ | **Orange/ | ||
+ | |||
+ | ==== Step 5: Creating a New Project ==== | ||
+ | |||
+ | Once you have the example program simpleLite working well with marker recognition and tracking, you can move onto creating your own project. For developing your own projects using the ARToolkit, I recommend using Visual Studio 2013 or higher. Visual Studio has great support for the ARToolkit SDK, and all of their example projects have been provided as Visual Studio projects to modify or use as reference. | ||
+ | |||
+ | To begin with creating a new project, simply open up Visual Studio and create an empty Visual Cpp project. Once you have created the empty project, you will need to add a .c file to the project. I named my file coordinate_tracking.c, | ||
+ | |||
+ | Once you have created the project, you will need to add the include and library directories to your project. Do this by right-clicking the project, and going to Properties. Under properties, look for the VCpp Directories tab. First click on the drop-down for include directories, | ||
+ | |||
+ | Finally, you need to copy over some data from the ARToolkit5 bin folder. First, copy the Data folder over to your project folder. Next, copy DSVL.dll, DSVLd.dll, ARvideo.dll, | ||
+ | |||
+ | Once you have all of this configured, you are ready to create your first program with the ARToolkit SDK. | ||
+ | |||
+ | ==== Step 6: Modifying the Simple Program to Track Coordinates ==== | ||
+ | |||
+ | Now that you have successfully setup, tested, and even created a new project with the ARToolkit SDK, you are finally ready to create custom code with the ARToolkit SDK. However, instead of creating all of the code from scratch, it is good to build off of the simpleTest.c program, provided with the ARToolkit SDK. | ||
+ | |||
+ | For reference on how the simpleTest.c program works wth the ARToolkit SDK, refer to [[https:// | ||
+ | |||
+ | **Adding Variables**\\ | ||
+ | Add these two variable declarations after line 31 of the simpleTest.c program. These lines will allow us to print the X and Y coordinates to the screen during processing. | ||
+ | <code c++> | ||
+ | 32 char xValue[256]; | ||
+ | 33 char yValue[256]; | ||
+ | </ | ||
+ | |||
+ | It is also necessary to add some variables to the mainLoop function. Add these variable declarations after line 140. Keep in mind, xReal and yReal are dependent on what the camera displays in your view, and its real-world size. | ||
+ | <code c++> | ||
+ | 141 double xCoord; | ||
+ | 142 double yCoord; | ||
+ | 143 double xReal = 38.5; | ||
+ | 144 double yReal = 26.5; | ||
+ | </ | ||
+ | |||
+ | **Flipping Video**\\ | ||
+ | Since the camera setup is one that is looking down onto the table from a reversed angle, we need to flip the video both horizontally and vertically. We can achieve this by adding 15 lines of code in the main function, after line 54. | ||
+ | <code c++> | ||
+ | 55 if (flipMode & AR_GL_FLIP_V) | ||
+ | 56 flipMode = flipMode & AR_GL_FLIP_H; | ||
+ | 57 else | ||
+ | 58 flipMode = flipMode | AR_GL_FLIP_V; | ||
+ | 59 | ||
+ | 60 argViewportSetFlipMode(vp, | ||
+ | 61 | ||
+ | 62 if (flipMode & AR_GL_FLIP_H) | ||
+ | 63 flipMode = flipMode & AR_GL_FLIP_V; | ||
+ | 64 else | ||
+ | 65 flipMode = flipMode | AR_GL_FLIP_H; | ||
+ | 66 | ||
+ | 67 argViewportSetFlipMode(vp, | ||
+ | </ | ||
+ | |||
+ | **Removing Current Output**\\ | ||
+ | Befoire adding new output of the X and Y coordinates, | ||
+ | <code c++> | ||
+ | 189 if (count % 60 == 0) { | ||
+ | 190 // | ||
+ | 191 | ||
+ | 192 } | ||
+ | 193 count++; | ||
+ | 194 // | ||
+ | 195 // | ||
+ | </ | ||
+ | |||
+ | For the error values, comment out lines 227, 229, and 230. | ||
+ | <code c++> | ||
+ | 227 // | ||
+ | 228 glColor3f(0.0f, | ||
+ | 229 // | ||
+ | 230 // | ||
+ | 231 // | ||
+ | </ | ||
+ | |||
+ | **Adding the X & Y Coordinates**\\ | ||
+ | Now we need to add the data for the X and Y coordinates to the screen. We can achieve this by adding 6 lines of code to the same area we just removed code from. Add these four lines after line 226. | ||
+ | <code c++> | ||
+ | 227 xCoord = markerInfo[k].pos[0]; | ||
+ | 228 yCoord = markerInfo[k].pos[1]; | ||
+ | 229 sprintf(yValue, | ||
+ | 230 sprintf(xValue, | ||
+ | </ | ||
+ | |||
+ | Now add these two lines after line 232. | ||
+ | <code c++> | ||
+ | 233 argDrawStringsByIdealPos(xValue, | ||
+ | 234 argDrawStringsByIdealPos(yValue, | ||
+ | </ | ||
+ | |||
+ | **Changing the Graphics Models**\\ | ||
+ | Now that we are tracking the coordinates well, we just need to change to original 3D cube graphics into a small 3D marker. This can be achieved by simply editing two lines of code, 388 and 389. | ||
+ | <code c++> | ||
+ | 388 glTranslatef(0.0f, | ||
+ | 389 glutSolidCube(10.0); | ||
+ | </ | ||
+ | |||
+ | |||
+ | Now the program should run smoothly and with accurate prediction of the real-world coordinates of the marker. Below is a video showing the coordinate tracking program in action. | ||
+ | |||
+ | {{ youtube> | ||
+ | |||
+ | ==== Step 7: Tracking Multiple Markers ==== | ||
+ | |||
+ | In order to use the ARToolkit SDK for tracking of objects or for any kind of computer vision application, | ||
+ | |||
+ | **Changing from pattern-detection to barcode-detection** | ||
+ | |||
+ | First you will need to remove the references to the pattern style, because we are no longer using pattern-detection. To do this, comment out the lines in the beginning of the program around line 25 (depending on your code) where it defines the pattern name, and where it initializes the pattern handle. | ||
+ | |||
+ | //# | ||
+ | | ||
+ | // | ||
+ | | ||
+ | Now you will need to add the barcode-detection to the main function. Places these two lines of code right before the function call for argMainLoop(): | ||
+ | |||
+ | arSetPatternDetectionMode(arHandle, | ||
+ | arSetMatrixCodeType(arHandle, | ||
+ | | ||
+ | This will setup the marker-detection into barcode-matrix mode, allowing the ARToolkit to detect these markers instead of the traditional style of marker. | ||
+ | |||
+ | **Tracking Coordinates of Multiple Markers** | ||
+ | |||
+ | In order to consistently track the coordinates of multiple markers, you will need to alter the detection algorithm to associate one barcode ID with one instance of an array for storing your coordinates. To do this, add these lines of code to the main detection loop, after the IDs and CF values are logged to the ARConsole: | ||
+ | |||
+ | for (h = 0; h < 7; h++) { | ||
+ | | ||
+ | if (markerInfo[j].idMatrix == h) { | ||
+ | yCoord[h] = (yReal / ysize)*(ysize - markerInfo[j].pos[1]); | ||
+ | xCoord[h] = (xReal / xsize)*(markerInfo[j].pos[0]); | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | Now we will be adding to this for loop in order to use our tracked coordinates for localization and navigation within an area. | ||
+ | |||
+ | ==== Step 8: Using Multiple Markers for Localization and Navigation ==== | ||
+ | |||
+ | In order to track the position of a robot or other vehicle using the ARToolkit, we will need to create an algorithm that creates relative coordinates for the robot based off of a known location of a stationary marker. This will allows us to create a kind of coordinate system that is independent of camera position or resolution. In order to do this, we will need to use one barcode marker (in most cases this will be number 0) fixed to a stationary location, and then reference this location in our code to get relative distances. This can be achieved by adding this block of code to the end of the for loop from the previous step: | ||
+ | |||
+ | if ((xCoord[0] != 0) && (yCoord[0] != 0) && (xCoord[h] < 1000) && (yCoord[h] < 1000) && (xCoord[h] > -1000) && (yCoord[h] > -1000)) { | ||
+ | xCoordRel[h] = xCoord[h] - xCoord[0]; | ||
+ | yCoordRel[h] = yCoord[h] - yCoord[0]; | ||
+ | ARLOG(" | ||
+ | sprintf(xValue[h], | ||
+ | sprintf(yValue[h], | ||
+ | argDrawStringsByIdealPos(xValue[h], | ||
+ | argDrawStringsByIdealPos(yValue[h], | ||
+ | } | ||
+ | |||
+ | This if statement will store the positions of these markers into a separate array for relative positions, ensuring that normal tracking is unaffected by this. This will also output those relative distances to the screen using the last 5 lines of code. Since this is located within that same for loop from above, this will keep everything sorted into the proper positions of their array. The conditional statement for this step is checking to make sure that the reference marker is stored, and that the marker it is trying to calculate for is being recognized correctly (hence the over 1000 value). Once you have added this to your code, you should | ||
+ | \\ | ||
+ | {{ youtube> | ||
+ | \\ | ||
+ | ===== Final Words ===== | ||
+ | |||
+ | This tutorial' | ||
+ | \\ | ||
+ | \\ | ||
+ | Speculating future work derived from this tutorial, includes Potential Fields using the ARToolkit, and Potential Fields with Humanoid Robots such as Darwin. In the big picture, the problem of object tracking can be solved with this tutorial. | ||
+ | \\ | ||
+ | \\ | ||
+ | For questions, clarifications, |
artoolkit_secret.txt · Last modified: 2016/11/16 20:03 by dwallace