diff --git a/_readme.md b/_readme.md new file mode 100644 index 0000000..a409bd4 --- /dev/null +++ b/_readme.md @@ -0,0 +1,47 @@ +opencv scripts for pick-and-place + +includes research materials where relevant + +targeted at mac OSX mavericks python2.7 + +opencv installed with homebrew.... each dependency was installed manually .. in this case, eigen, qt, and a reinstall of cmake. in some cases, numpy / scipy will need to be installed as well + +to do: +___________________ + +auto-range for thresholding based on expected values + +~~find contours~~ + +mask object + +find coordinates of masked object + +integrate the components into a single toolchain + + +video +-------------------- +
+
3dcam
+
supports the kinect through libfreenect, tweaked some fairly straightforward video feed example, powered from a desktop power supply
+
cntr
+
does single largest blob tracking in video, look for the blue dot
+using static images +-------------------- +
cell
+
usage: `python cell.py `
+
the image should be within ~/projects/cv/images and should be already thresholded
+
the bread-and-butter of this project: working on actually identifying the cell on a field
+
thresholding
+
the lynchpin of the rest of the software, performs thresholding operations to reduce noise
+
usage: `python thresholding.py `
+
displays the thresholded image and saves it
+
corner.py
+
foundation functions for edge detection sloppy but reasonably quick
+
good_corner
+
just a demo from the tutorial... pretty accurate but savagely slow.
+
contours
+
an attempt to define the longest continuous rect
+
square and sq2
+
attempts to find black square
\ No newline at end of file diff --git a/command_line_usage.png b/command_line_usage.png new file mode 100644 index 0000000..dcb54e6 Binary files /dev/null and b/command_line_usage.png differ diff --git a/feature_mapping.png b/feature_mapping.png new file mode 100644 index 0000000..96449dc Binary files /dev/null and b/feature_mapping.png differ diff --git a/src/c++/SURF_Homography b/src/c++/SURF_Homography new file mode 100755 index 0000000..0d51a67 Binary files /dev/null and b/src/c++/SURF_Homography differ diff --git a/src/c++/SURF_Homography.cpp b/src/c++/SURF_Homography.cpp new file mode 100644 index 0000000..47bc3ec --- /dev/null +++ b/src/c++/SURF_Homography.cpp @@ -0,0 +1,125 @@ +/** + * @file SURF_Homography + * @brief SURF detector + descriptor + FLANN Matcher + FindHomography + * @author A. Huaman + */ + +#include +#include +#include "opencv2/core/core.hpp" +#include "opencv2/features2d/features2d.hpp" +#include "opencv2/highgui/highgui.hpp" +#include "opencv2/calib3d/calib3d.hpp" +#include "opencv2/nonfree/features2d.hpp" + +using namespace std; +using namespace cv; + +void readme(); + +/** + * @function main + * @brief Main function + */ +int main( int argc, char** argv ) +{ + if( argc != 3 ) + { readme(); return -1; } + + Mat img_object = imread( argv[1], IMREAD_GRAYSCALE ); + Mat img_scene = imread( argv[2], IMREAD_GRAYSCALE ); + + if( !img_object.data || !img_scene.data ) + { std::cout<< " --(!) Error reading images " << std::endl; return -1; } + + //-- Step 1: Detect the keypoints using SURF Detector + int minHessian = 400; + + SurfFeatureDetector detector( minHessian ); + + std::vector keypoints_object, keypoints_scene; + + detector.detect( img_object, keypoints_object ); + detector.detect( img_scene, keypoints_scene ); + + //-- Step 2: Calculate descriptors (feature vectors) + SurfDescriptorExtractor extractor; + + Mat descriptors_object, descriptors_scene; + + extractor.compute( img_object, keypoints_object, descriptors_object ); + extractor.compute( img_scene, keypoints_scene, descriptors_scene ); + + //-- Step 3: Matching descriptor vectors using FLANN matcher + FlannBasedMatcher matcher; + std::vector< DMatch > matches; + matcher.match( descriptors_object, descriptors_scene, matches ); + + double max_dist = 0; double min_dist = 100; + + //-- Quick calculation of max and min distances between keypoints + for( int i = 0; i < descriptors_object.rows; i++ ) + { double dist = matches[i].distance; + if( dist < min_dist ) min_dist = dist; + if( dist > max_dist ) max_dist = dist; + } + + printf("-- Max dist : %f \n", max_dist ); + printf("-- Min dist : %f \n", min_dist ); + + //-- Draw only "good" matches (i.e. whose distance is less than 3*min_dist ) + std::vector< DMatch > good_matches; + + for( int i = 0; i < descriptors_object.rows; i++ ) + { if( matches[i].distance < 3*min_dist ) + { good_matches.push_back( matches[i]); } + } + + Mat img_matches; + drawMatches( img_object, keypoints_object, img_scene, keypoints_scene, + good_matches, img_matches, Scalar::all(-1), Scalar::all(-1), + vector(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS ); + + + //-- Localize the object from img_1 in img_2 + std::vector obj; + std::vector scene; + + for( size_t i = 0; i < good_matches.size(); i++ ) + { + //-- Get the keypoints from the good matches + obj.push_back( keypoints_object[ good_matches[i].queryIdx ].pt ); + scene.push_back( keypoints_scene[ good_matches[i].trainIdx ].pt ); + } + + Mat H = findHomography( obj, scene, RANSAC ); + + //-- Get the corners from the image_1 ( the object to be "detected" ) + std::vector obj_corners(4); + obj_corners[0] = Point(0,0); obj_corners[1] = Point( img_object.cols, 0 ); + obj_corners[2] = Point( img_object.cols, img_object.rows ); obj_corners[3] = Point( 0, img_object.rows ); + std::vector scene_corners(4); + + perspectiveTransform( obj_corners, scene_corners, H); + + + //-- Draw lines between the corners (the mapped object in the scene - image_2 ) + Point2f offset( (float)img_object.cols, 0); + line( img_matches, scene_corners[0] + offset, scene_corners[1] + offset, Scalar(0, 255, 0), 4 ); + line( img_matches, scene_corners[1] + offset, scene_corners[2] + offset, Scalar( 0, 255, 0), 4 ); + line( img_matches, scene_corners[2] + offset, scene_corners[3] + offset, Scalar( 0, 255, 0), 4 ); + line( img_matches, scene_corners[3] + offset, scene_corners[0] + offset, Scalar( 0, 255, 0), 4 ); + + //-- Show detected matches + imshow( "Good Matches & Object detection", img_matches ); + + waitKey(0); + + return 0; +} + +/** + * @function readme + */ +void readme() +{ std::cout << " Usage: ./SURF_Homography " << std::endl; } diff --git a/src/c++/bound.jpg b/src/c++/bound.jpg new file mode 100644 index 0000000..6e24b57 Binary files /dev/null and b/src/c++/bound.jpg differ diff --git a/src/c++/img1.jpg b/src/c++/img1.jpg new file mode 100644 index 0000000..ac4e82e Binary files /dev/null and b/src/c++/img1.jpg differ diff --git a/src/c++/img10.jpg b/src/c++/img10.jpg new file mode 100644 index 0000000..e211461 Binary files /dev/null and b/src/c++/img10.jpg differ diff --git a/src/c++/img2.jpg b/src/c++/img2.jpg new file mode 100644 index 0000000..28e4043 Binary files /dev/null and b/src/c++/img2.jpg differ diff --git a/src/c++/img2_blur_1.jpg b/src/c++/img2_blur_1.jpg new file mode 100644 index 0000000..1fa845f Binary files /dev/null and b/src/c++/img2_blur_1.jpg differ diff --git a/src/c++/img3.jpg b/src/c++/img3.jpg new file mode 100644 index 0000000..d4d761b Binary files /dev/null and b/src/c++/img3.jpg differ diff --git a/src/c++/img4.jpg b/src/c++/img4.jpg new file mode 100644 index 0000000..0abb2ce Binary files /dev/null and b/src/c++/img4.jpg differ diff --git a/src/c++/img5.jpg b/src/c++/img5.jpg new file mode 100644 index 0000000..fe73176 Binary files /dev/null and b/src/c++/img5.jpg differ diff --git a/src/c++/img6.jpg b/src/c++/img6.jpg new file mode 100644 index 0000000..3f89c72 Binary files /dev/null and b/src/c++/img6.jpg differ diff --git a/src/c++/img7.jpg b/src/c++/img7.jpg new file mode 100644 index 0000000..308ed60 Binary files /dev/null and b/src/c++/img7.jpg differ diff --git a/src/c++/img8.jpg b/src/c++/img8.jpg new file mode 100644 index 0000000..69d90a4 Binary files /dev/null and b/src/c++/img8.jpg differ diff --git a/src/c++/img9.jpg b/src/c++/img9.jpg new file mode 100644 index 0000000..c92adb8 Binary files /dev/null and b/src/c++/img9.jpg differ diff --git a/src/c++/makescript.sh b/src/c++/makescript.sh new file mode 100755 index 0000000..0faf414 --- /dev/null +++ b/src/c++/makescript.sh @@ -0,0 +1,4 @@ +# Todo: make a real makefile + g++ -Wall -Wextra `pkg-config --cflags --libs opencv` -o SURF_Homography SURF_Homography.cpp + + diff --git a/src/c++/t-img10.jpg b/src/c++/t-img10.jpg new file mode 100644 index 0000000..284e5f0 Binary files /dev/null and b/src/c++/t-img10.jpg differ diff --git a/src/c++/t-img2.jpg b/src/c++/t-img2.jpg new file mode 100644 index 0000000..76b473e Binary files /dev/null and b/src/c++/t-img2.jpg differ diff --git a/src/c++/t-img4.jpg b/src/c++/t-img4.jpg new file mode 100644 index 0000000..75269f0 Binary files /dev/null and b/src/c++/t-img4.jpg differ diff --git a/src/c++/template.jpg b/src/c++/template.jpg new file mode 100644 index 0000000..62cb1b5 Binary files /dev/null and b/src/c++/template.jpg differ diff --git a/src/c++/template_blur_1.jpg b/src/c++/template_blur_1.jpg new file mode 100644 index 0000000..cb0b8ca Binary files /dev/null and b/src/c++/template_blur_1.jpg differ diff --git a/src/c++/template_bottom.jpg b/src/c++/template_bottom.jpg new file mode 100644 index 0000000..e375354 Binary files /dev/null and b/src/c++/template_bottom.jpg differ diff --git a/src/c++/template_glue.jpg b/src/c++/template_glue.jpg new file mode 100644 index 0000000..2522ea9 Binary files /dev/null and b/src/c++/template_glue.jpg differ diff --git a/src/c++/template_just_box.jpg b/src/c++/template_just_box.jpg new file mode 100644 index 0000000..2c7753e Binary files /dev/null and b/src/c++/template_just_box.jpg differ diff --git a/src/c++/template_just_inner.jpg b/src/c++/template_just_inner.jpg new file mode 100644 index 0000000..82a7b74 Binary files /dev/null and b/src/c++/template_just_inner.jpg differ diff --git a/src/c++/template_modded.jpg b/src/c++/template_modded.jpg new file mode 100644 index 0000000..290f53f Binary files /dev/null and b/src/c++/template_modded.jpg differ diff --git a/src/c++/template_modded_box.jpg b/src/c++/template_modded_box.jpg new file mode 100644 index 0000000..4666533 Binary files /dev/null and b/src/c++/template_modded_box.jpg differ diff --git a/src/c++/template_rim.jpg b/src/c++/template_rim.jpg new file mode 100644 index 0000000..dd51820 Binary files /dev/null and b/src/c++/template_rim.jpg differ diff --git a/src/canny.py b/src/python/canny.py similarity index 100% rename from src/canny.py rename to src/python/canny.py diff --git a/src/cell.py b/src/python/cell.py similarity index 100% rename from src/cell.py rename to src/python/cell.py diff --git a/src/contours.py b/src/python/contours.py similarity index 100% rename from src/contours.py rename to src/python/contours.py diff --git a/src/corner.py b/src/python/corner.py similarity index 100% rename from src/corner.py rename to src/python/corner.py diff --git a/src/cvdemo.py b/src/python/cvdemo.py similarity index 100% rename from src/cvdemo.py rename to src/python/cvdemo.py diff --git a/src/dem.py b/src/python/dem.py similarity index 100% rename from src/dem.py rename to src/python/dem.py diff --git a/src/good_corner.py b/src/python/good_corner.py similarity index 100% rename from src/good_corner.py rename to src/python/good_corner.py diff --git a/src/mask.py b/src/python/mask.py similarity index 100% rename from src/mask.py rename to src/python/mask.py diff --git a/src/sq2.py b/src/python/sq2.py similarity index 100% rename from src/sq2.py rename to src/python/sq2.py diff --git a/src/squares.py b/src/python/squares.py similarity index 100% rename from src/squares.py rename to src/python/squares.py diff --git a/src/thresholding.py b/src/python/thresholding.py similarity index 100% rename from src/thresholding.py rename to src/python/thresholding.py