ruby-opencv 0.0.10 → 0.0.11.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +6 -14
- data/Manifest.txt +32 -8
- data/README.md +1 -1
- data/examples/alpha_blend.rb +2 -2
- data/examples/contours/bounding-box-detect-canny.rb +0 -0
- data/examples/contours/contour_retrieval_modes.rb +0 -0
- data/examples/convexhull.rb +0 -0
- data/examples/face_detect.rb +0 -0
- data/examples/facerec/create_csv.rb +43 -0
- data/examples/facerec/facerec_eigenfaces.rb +132 -0
- data/examples/facerec/facerec_fisherfaces.rb +131 -0
- data/examples/facerec/facerec_lbph.rb +116 -0
- data/examples/facerec/readme.md +111 -0
- data/examples/find_obj.rb +2 -2
- data/examples/houghcircle.rb +1 -1
- data/examples/{box.png → images/box.png} +0 -0
- data/examples/{box_in_scene.png → images/box_in_scene.png} +0 -0
- data/examples/{inpaint.png → images/inpaint.png} +0 -0
- data/examples/images/lena-256x256.jpg +0 -0
- data/examples/images/lena-eyes.jpg +0 -0
- data/examples/{lenna-rotated.jpg → images/lenna-rotated.jpg} +0 -0
- data/examples/{lenna.jpg → images/lenna.jpg} +0 -0
- data/examples/{stuff.jpg → images/stuff.jpg} +0 -0
- data/examples/{tiffany.jpg → images/tiffany.jpg} +0 -0
- data/examples/inpaint.rb +1 -1
- data/examples/match_kdtree.rb +2 -2
- data/examples/match_template.rb +26 -0
- data/examples/{matching_to_many_images.rb → matching_to_many_images/matching_to_many_images.rb} +3 -3
- data/examples/matching_to_many_images/query.png +0 -0
- data/examples/matching_to_many_images/train/1.png +0 -0
- data/examples/matching_to_many_images/train/2.png +0 -0
- data/examples/matching_to_many_images/train/3.png +0 -0
- data/examples/matching_to_many_images/train/trainImages.txt +0 -0
- data/examples/paint.rb +0 -0
- data/examples/snake.rb +0 -0
- data/ext/opencv/algorithm.cpp +286 -0
- data/ext/opencv/algorithm.h +38 -0
- data/ext/opencv/cvmat.cpp +205 -76
- data/ext/opencv/cvmat.h +8 -1
- data/ext/opencv/eigenfaces.cpp +67 -0
- data/ext/opencv/eigenfaces.h +30 -0
- data/ext/opencv/extconf.rb +0 -0
- data/ext/opencv/facerecognizer.cpp +174 -0
- data/ext/opencv/facerecognizer.h +46 -0
- data/ext/opencv/fisherfaces.cpp +67 -0
- data/ext/opencv/fisherfaces.h +30 -0
- data/ext/opencv/lbph.cpp +70 -0
- data/ext/opencv/lbph.h +30 -0
- data/ext/opencv/opencv.cpp +51 -1
- data/ext/opencv/opencv.h +6 -0
- data/lib/opencv.rb +0 -0
- data/lib/opencv/version.rb +1 -1
- data/ruby-opencv.gemspec +8 -7
- data/test/eigenfaces_save.xml +7524 -0
- data/test/fisherfaces_save.xml +7530 -0
- data/test/helper.rb +0 -0
- data/test/lbph_save.xml +4304 -0
- data/test/runner.rb +0 -0
- data/test/test_curve.rb +0 -0
- data/test/test_cvavgcomp.rb +0 -0
- data/test/test_cvbox2d.rb +0 -0
- data/test/test_cvcapture.rb +0 -0
- data/test/test_cvchain.rb +0 -0
- data/test/test_cvcircle32f.rb +0 -0
- data/test/test_cvconnectedcomp.rb +0 -0
- data/test/test_cvcontour.rb +0 -0
- data/test/test_cvcontourtree.rb +0 -0
- data/test/test_cverror.rb +0 -0
- data/test/test_cvfeaturetree.rb +0 -0
- data/test/test_cvfont.rb +0 -0
- data/test/test_cvhaarclassifiercascade.rb +0 -0
- data/test/test_cvhistogram.rb +0 -0
- data/test/test_cvhumoments.rb +0 -0
- data/test/test_cvline.rb +0 -0
- data/test/test_cvmat.rb +72 -16
- data/test/test_cvmat_drawing.rb +0 -0
- data/test/test_cvmat_dxt.rb +0 -0
- data/test/test_cvmat_imageprocessing.rb +72 -2
- data/test/test_cvmat_matching.rb +1 -1
- data/test/test_cvmoments.rb +0 -0
- data/test/test_cvpoint.rb +0 -0
- data/test/test_cvpoint2d32f.rb +0 -0
- data/test/test_cvpoint3d32f.rb +0 -0
- data/test/test_cvrect.rb +0 -0
- data/test/test_cvscalar.rb +0 -0
- data/test/test_cvseq.rb +0 -0
- data/test/test_cvsize.rb +0 -0
- data/test/test_cvsize2d32f.rb +0 -0
- data/test/test_cvslice.rb +0 -0
- data/test/test_cvsurfparams.rb +0 -0
- data/test/test_cvsurfpoint.rb +0 -0
- data/test/test_cvtermcriteria.rb +0 -0
- data/test/test_cvtwopoints.rb +0 -0
- data/test/test_cvvideowriter.rb +0 -0
- data/test/test_eigenfaces.rb +93 -0
- data/test/test_fisherfaces.rb +93 -0
- data/test/test_iplconvkernel.rb +0 -0
- data/test/test_iplimage.rb +0 -4
- data/test/test_lbph.rb +152 -0
- data/test/test_mouseevent.rb +0 -0
- data/test/test_opencv.rb +33 -4
- data/test/test_pointset.rb +7 -5
- data/test/test_preliminary.rb +0 -0
- data/test/test_trackbar.rb +0 -0
- data/test/test_window.rb +0 -0
- metadata +84 -56
@@ -0,0 +1,38 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
algorithm.h
|
4
|
+
|
5
|
+
$Author: ser1zw $
|
6
|
+
|
7
|
+
Copyright (C) 2013 ser1zw
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_ALGORITHM_H
|
11
|
+
#define RUBY_OPENCV_ALGORITHM_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_ALGORITHM namespace cAlgorithm {
|
16
|
+
#define __NAMESPACE_END_ALGORITM }
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_ALGORITHM
|
20
|
+
|
21
|
+
VALUE rb_class();
|
22
|
+
|
23
|
+
void define_ruby_class();
|
24
|
+
|
25
|
+
__NAMESPACE_END_ALGORITM
|
26
|
+
|
27
|
+
inline cv::Algorithm*
|
28
|
+
ALGORITHM(VALUE object)
|
29
|
+
{
|
30
|
+
cv::Algorithm *ptr;
|
31
|
+
Data_Get_Struct(object, cv::Algorithm, ptr);
|
32
|
+
return ptr;
|
33
|
+
}
|
34
|
+
|
35
|
+
__NAMESPACE_END_OPENCV
|
36
|
+
|
37
|
+
#endif // RUBY_OPENCV_ALGORITHM_H
|
38
|
+
|
data/ext/opencv/cvmat.cpp
CHANGED
@@ -254,7 +254,7 @@ void define_ruby_class()
|
|
254
254
|
rb_define_method(rb_klass, "range", RUBY_METHOD_FUNC(rb_range), 2);
|
255
255
|
rb_define_method(rb_klass, "range!", RUBY_METHOD_FUNC(rb_range_bang), 2);
|
256
256
|
|
257
|
-
rb_define_method(rb_klass, "reshape", RUBY_METHOD_FUNC(rb_reshape), 1);
|
257
|
+
rb_define_method(rb_klass, "reshape", RUBY_METHOD_FUNC(rb_reshape), -1);
|
258
258
|
rb_define_method(rb_klass, "repeat", RUBY_METHOD_FUNC(rb_repeat), 1);
|
259
259
|
rb_define_method(rb_klass, "flip", RUBY_METHOD_FUNC(rb_flip), -1);
|
260
260
|
rb_define_method(rb_klass, "flip!", RUBY_METHOD_FUNC(rb_flip_bang), -1);
|
@@ -352,6 +352,7 @@ void define_ruby_class()
|
|
352
352
|
rb_define_method(rb_klass, "resize", RUBY_METHOD_FUNC(rb_resize), -1);
|
353
353
|
rb_define_method(rb_klass, "warp_affine", RUBY_METHOD_FUNC(rb_warp_affine), -1);
|
354
354
|
rb_define_singleton_method(rb_klass, "rotation_matrix2D", RUBY_METHOD_FUNC(rb_rotation_matrix2D), 3);
|
355
|
+
rb_define_singleton_method(rb_klass, "get_perspective_transform", RUBY_METHOD_FUNC(rb_get_perspective_transform), 2);
|
355
356
|
rb_define_method(rb_klass, "warp_perspective", RUBY_METHOD_FUNC(rb_warp_perspective), -1);
|
356
357
|
rb_define_singleton_method(rb_klass, "find_homography", RUBY_METHOD_FUNC(rb_find_homograpy), -1);
|
357
358
|
rb_define_method(rb_klass, "remap", RUBY_METHOD_FUNC(rb_remap), -1);
|
@@ -392,6 +393,7 @@ void define_ruby_class()
|
|
392
393
|
rb_define_method(rb_klass, "inpaint", RUBY_METHOD_FUNC(rb_inpaint), 3);
|
393
394
|
|
394
395
|
rb_define_method(rb_klass, "equalize_hist", RUBY_METHOD_FUNC(rb_equalize_hist), 0);
|
396
|
+
rb_define_method(rb_klass, "apply_color_map", RUBY_METHOD_FUNC(rb_apply_color_map), 1);
|
395
397
|
rb_define_method(rb_klass, "match_template", RUBY_METHOD_FUNC(rb_match_template), -1);
|
396
398
|
rb_define_method(rb_klass, "match_shapes", RUBY_METHOD_FUNC(rb_match_shapes), -1);
|
397
399
|
rb_define_method(rb_klass, "match_descriptors", RUBY_METHOD_FUNC(rb_match_descriptors), -1);
|
@@ -411,6 +413,9 @@ void define_ruby_class()
|
|
411
413
|
|
412
414
|
rb_define_method(rb_klass, "extract_surf", RUBY_METHOD_FUNC(rb_extract_surf), -1);
|
413
415
|
|
416
|
+
rb_define_method(rb_klass, "subspace_project", RUBY_METHOD_FUNC(rb_subspace_project), 2);
|
417
|
+
rb_define_method(rb_klass, "subspace_reconstruct", RUBY_METHOD_FUNC(rb_subspace_reconstruct), 2);
|
418
|
+
|
414
419
|
rb_define_method(rb_klass, "save_image", RUBY_METHOD_FUNC(rb_save_image), -1);
|
415
420
|
rb_define_alias(rb_klass, "save", "save_image");
|
416
421
|
|
@@ -1598,25 +1603,22 @@ rb_range_bang(VALUE self, VALUE start, VALUE end)
|
|
1598
1603
|
|
1599
1604
|
/*
|
1600
1605
|
* call-seq:
|
1601
|
-
* reshape(
|
1606
|
+
* reshape(cn, rows=0) -> cvmat(refer self)
|
1602
1607
|
*
|
1603
1608
|
* Change shape of matrix/image without copying data.
|
1604
1609
|
*
|
1605
|
-
*
|
1606
|
-
*
|
1607
|
-
*
|
1608
|
-
* ch1 = mat.reshape(:channel => 1) #=> 9x9 1-channel matrix
|
1610
|
+
* Parameter:
|
1611
|
+
* * cn - New number of channels. If the parameter is 0, the number of channels remains the same.
|
1612
|
+
* * rows - New number of rows. If the parameter is 0, the number of rows remains the same.
|
1609
1613
|
*/
|
1610
1614
|
VALUE
|
1611
|
-
rb_reshape(VALUE
|
1615
|
+
rb_reshape(int argc, VALUE *argv, VALUE self)
|
1612
1616
|
{
|
1613
|
-
|
1614
|
-
VALUE channel = LOOKUP_HASH(hash, "channel");
|
1615
|
-
VALUE rows = LOOKUP_HASH(hash, "rows");
|
1617
|
+
VALUE cn, rows;
|
1616
1618
|
CvMat *mat = NULL;
|
1619
|
+
rb_scan_args(argc, argv, "11", &cn, &rows);
|
1617
1620
|
try {
|
1618
|
-
mat = cvReshape(CVARR(self), RB_CVALLOC(CvMat),
|
1619
|
-
NIL_P(rows) ? 0 : NUM2INT(rows));
|
1621
|
+
mat = cvReshape(CVARR(self), RB_CVALLOC(CvMat), NUM2INT(cn), IF_INT(rows, 0));
|
1620
1622
|
}
|
1621
1623
|
catch (cv::Exception& e) {
|
1622
1624
|
if (mat != NULL)
|
@@ -2378,38 +2380,50 @@ rb_abs_diff(VALUE self, VALUE val)
|
|
2378
2380
|
|
2379
2381
|
/*
|
2380
2382
|
* call-seq:
|
2381
|
-
* normalize(
|
2383
|
+
* normalize(alpha=1, beta=0, norm_type=NORM_L2, dtype=-1, mask=nil) -> cvmat
|
2384
|
+
*
|
2385
|
+
* Normalizes the norm or value range of an array.
|
2382
2386
|
*
|
2383
|
-
*
|
2387
|
+
* Parameters:
|
2388
|
+
* * alpha - norm value to normalize to or the lower range boundary in case of the range normalization.
|
2389
|
+
* * beta - upper range boundary in case of the range normalization; it is not used for the norm normalization.
|
2390
|
+
* * norm_type - normalization type.
|
2391
|
+
* * dtype - when negative, the output array has the same type as src; otherwise, it has the same number of channels as src and the depth
|
2392
|
+
* * mask - optional operation mask.
|
2384
2393
|
*/
|
2385
2394
|
VALUE
|
2386
2395
|
rb_normalize(int argc, VALUE *argv, VALUE self)
|
2387
2396
|
{
|
2388
|
-
VALUE
|
2389
|
-
rb_scan_args(argc, argv, "
|
2390
|
-
|
2391
|
-
|
2392
|
-
|
2393
|
-
|
2394
|
-
|
2395
|
-
VALUE
|
2397
|
+
VALUE alpha_val, beta_val, norm_type_val, dtype_val, mask_val;
|
2398
|
+
rb_scan_args(argc, argv, "05", &alpha_val, &beta_val, &norm_type_val, &dtype_val, &mask_val);
|
2399
|
+
|
2400
|
+
double alpha = NIL_P(alpha_val) ? 1.0 : NUM2DBL(alpha_val);
|
2401
|
+
double beta = NIL_P(beta_val) ? 0.0 : NUM2DBL(beta_val);
|
2402
|
+
int norm_type = NIL_P(norm_type_val) ? cv::NORM_L2 : NUM2INT(norm_type_val);
|
2403
|
+
int dtype = NIL_P(dtype_val) ? -1 : NUM2INT(dtype_val);
|
2404
|
+
VALUE dst;
|
2405
|
+
|
2396
2406
|
try {
|
2397
|
-
|
2398
|
-
cv::Mat
|
2399
|
-
|
2400
|
-
if (NIL_P(
|
2401
|
-
cv::normalize(
|
2407
|
+
cv::Mat self_mat(CVMAT(self));
|
2408
|
+
cv::Mat dst_mat;
|
2409
|
+
|
2410
|
+
if (NIL_P(mask_val)) {
|
2411
|
+
cv::normalize(self_mat, dst_mat, alpha, beta, norm_type, dtype);
|
2402
2412
|
}
|
2403
2413
|
else {
|
2404
|
-
cv::Mat
|
2405
|
-
cv::normalize(
|
2414
|
+
cv::Mat mask(MASK(mask_val));
|
2415
|
+
cv::normalize(self_mat, dst_mat, alpha, beta, norm_type, dtype, mask);
|
2406
2416
|
}
|
2407
|
-
|
2408
|
-
|
2417
|
+
dst = new_mat_kind_object(cvGetSize(CVARR(self)), self, dst_mat.depth(), dst_mat.channels());
|
2418
|
+
|
2419
|
+
CvMat tmp = dst_mat;
|
2420
|
+
cvCopy(&tmp, CVMAT(dst));
|
2421
|
+
}
|
2422
|
+
catch (cv::Exception& e) {
|
2409
2423
|
raise_cverror(e);
|
2410
2424
|
}
|
2411
2425
|
|
2412
|
-
return
|
2426
|
+
return dst;
|
2413
2427
|
}
|
2414
2428
|
|
2415
2429
|
/*
|
@@ -4040,6 +4054,40 @@ rb_rotation_matrix2D(VALUE self, VALUE center, VALUE angle, VALUE scale)
|
|
4040
4054
|
return map_matrix;
|
4041
4055
|
}
|
4042
4056
|
|
4057
|
+
/*
|
4058
|
+
* call-seq:
|
4059
|
+
* CvMat.get_perspective_transform(<i>from_points,to_points</i>) -> cvmat
|
4060
|
+
*
|
4061
|
+
* Calculates a perspective transform from four pairs of the corresponding points.
|
4062
|
+
* Returns a matrix suitable for use with warp_perspective
|
4063
|
+
*/
|
4064
|
+
VALUE
|
4065
|
+
rb_get_perspective_transform(VALUE self, VALUE source, VALUE dest)
|
4066
|
+
{
|
4067
|
+
Check_Type(source, T_ARRAY);
|
4068
|
+
Check_Type(dest, T_ARRAY);
|
4069
|
+
|
4070
|
+
int count = RARRAY_LEN(source);
|
4071
|
+
|
4072
|
+
CvPoint2D32f* source_buff = ALLOCA_N(CvPoint2D32f, count);
|
4073
|
+
CvPoint2D32f* dest_buff = ALLOCA_N(CvPoint2D32f, count);
|
4074
|
+
|
4075
|
+
for (int i = 0; i < count; i++) {
|
4076
|
+
source_buff[i] = *(CVPOINT2D32F(RARRAY_PTR(source)[i]));
|
4077
|
+
dest_buff[i] = *(CVPOINT2D32F(RARRAY_PTR(dest)[i]));
|
4078
|
+
}
|
4079
|
+
|
4080
|
+
VALUE map_matrix = new_object(cvSize(3, 3), CV_MAKETYPE(CV_32F, 1));
|
4081
|
+
|
4082
|
+
try {
|
4083
|
+
cvGetPerspectiveTransform(source_buff, dest_buff, CVMAT(map_matrix));
|
4084
|
+
}
|
4085
|
+
catch (cv::Exception& e) {
|
4086
|
+
raise_cverror(e);
|
4087
|
+
}
|
4088
|
+
return map_matrix;
|
4089
|
+
}
|
4090
|
+
|
4043
4091
|
/*
|
4044
4092
|
* call-seq:
|
4045
4093
|
* warp_perspective(<i>map_matrix[,flags = CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS][,fillval=0])</i>) -> cvmat
|
@@ -5198,6 +5246,35 @@ rb_equalize_hist(VALUE self)
|
|
5198
5246
|
return dest;
|
5199
5247
|
}
|
5200
5248
|
|
5249
|
+
/*
|
5250
|
+
* call-seq:
|
5251
|
+
* apply_color_map(colormap) -> cvmat
|
5252
|
+
*
|
5253
|
+
* Applies a GNU Octave/MATLAB equivalent colormap on a given image.
|
5254
|
+
*
|
5255
|
+
* Parameters:
|
5256
|
+
* colormap - The colormap to apply.
|
5257
|
+
*/
|
5258
|
+
VALUE
|
5259
|
+
rb_apply_color_map(VALUE self, VALUE colormap)
|
5260
|
+
{
|
5261
|
+
VALUE dst;
|
5262
|
+
try {
|
5263
|
+
cv::Mat dst_mat;
|
5264
|
+
cv::Mat self_mat(CVMAT(self));
|
5265
|
+
|
5266
|
+
cv::applyColorMap(self_mat, dst_mat, NUM2INT(colormap));
|
5267
|
+
CvMat tmp = dst_mat;
|
5268
|
+
dst = new_object(tmp.rows, tmp.cols, tmp.type);
|
5269
|
+
cvCopy(&tmp, CVMAT(dst));
|
5270
|
+
}
|
5271
|
+
catch (cv::Exception& e) {
|
5272
|
+
raise_cverror(e);
|
5273
|
+
}
|
5274
|
+
|
5275
|
+
return dst;
|
5276
|
+
}
|
5277
|
+
|
5201
5278
|
/*
|
5202
5279
|
* call-seq:
|
5203
5280
|
* match_template(<i>template[,method = :sqdiff]</i>) -> cvmat(result)
|
@@ -5309,7 +5386,6 @@ rb_match_descriptors(int argc, VALUE *argv, VALUE self)
|
|
5309
5386
|
{
|
5310
5387
|
VALUE images, detector_type, descriptor_type, matcher_type;
|
5311
5388
|
rb_scan_args(argc, argv, "13", &images, &detector_type, &descriptor_type, &matcher_type);
|
5312
|
-
|
5313
5389
|
if (RARRAY_LEN(images) == 0) {
|
5314
5390
|
return rb_hash_new();
|
5315
5391
|
}
|
@@ -5323,54 +5399,58 @@ rb_match_descriptors(int argc, VALUE *argv, VALUE self)
|
|
5323
5399
|
matcher_type = rb_str_new2("FlannBased");
|
5324
5400
|
}
|
5325
5401
|
|
5326
|
-
|
5327
|
-
std::vector<cv::Mat> trainImages;
|
5328
|
-
for(int i=0; i < RARRAY_LEN(images); i++) {
|
5329
|
-
trainImages.push_back(CVMAT_WITH_CHECK(RARRAY_PTR(images)[i]));
|
5330
|
-
}
|
5331
|
-
|
5332
|
-
cv::Ptr<cv::FeatureDetector> featureDetector = cv::FeatureDetector::create(RSTRING_PTR(detector_type));
|
5333
|
-
if (featureDetector.empty()) {
|
5334
|
-
rb_raise(rb_eArgError, "Could not create feature detector by given detector type: %s", RSTRING_PTR(detector_type));
|
5335
|
-
}
|
5336
|
-
cv::Ptr<cv::DescriptorExtractor> descriptorExtractor = cv::DescriptorExtractor::create(RSTRING_PTR(descriptor_type));
|
5337
|
-
if (descriptorExtractor.empty()) {
|
5338
|
-
rb_raise(rb_eArgError, "Could not create descriptor extractor by given descriptor type: %s", RSTRING_PTR(descriptor_type));
|
5339
|
-
}
|
5340
|
-
cv::Ptr<cv::DescriptorMatcher> descriptorMatcher;
|
5402
|
+
VALUE _matches = rb_hash_new();
|
5341
5403
|
try {
|
5342
|
-
|
5343
|
-
|
5344
|
-
|
5345
|
-
|
5346
|
-
|
5347
|
-
|
5348
|
-
std::vector<cv::KeyPoint> queryKeypoints;
|
5349
|
-
std::vector<std::vector<cv::KeyPoint> > trainKeypoints;
|
5350
|
-
featureDetector->detect(queryImage, queryKeypoints);
|
5351
|
-
featureDetector->detect(trainImages, trainKeypoints);
|
5352
|
-
|
5353
|
-
cv::Mat queryDescriptors;
|
5354
|
-
std::vector<cv::Mat> trainDescriptors;
|
5355
|
-
descriptorExtractor->compute(queryImage, queryKeypoints, queryDescriptors);
|
5356
|
-
descriptorExtractor->compute(trainImages, trainKeypoints, trainDescriptors);
|
5404
|
+
cv::Mat queryImage(CVMAT(self));
|
5405
|
+
std::vector<cv::Mat> trainImages;
|
5406
|
+
for(int i = 0, n = RARRAY_LEN(images); i < n; i++) {
|
5407
|
+
trainImages.push_back(CVMAT_WITH_CHECK(RARRAY_PTR(images)[i]));
|
5408
|
+
}
|
5357
5409
|
|
5358
|
-
|
5359
|
-
|
5360
|
-
|
5361
|
-
|
5410
|
+
cv::Ptr<cv::FeatureDetector> featureDetector = cv::FeatureDetector::create(StringValueCStr(detector_type));
|
5411
|
+
if (featureDetector.empty()) {
|
5412
|
+
rb_raise(rb_eArgError, "Could not create feature detector by given detector type: %s", StringValueCStr(detector_type));
|
5413
|
+
}
|
5414
|
+
cv::Ptr<cv::DescriptorExtractor> descriptorExtractor = cv::DescriptorExtractor::create(StringValueCStr(descriptor_type));
|
5415
|
+
if (descriptorExtractor.empty()) {
|
5416
|
+
rb_raise(rb_eArgError, "Could not create descriptor extractor by given descriptor type: %s", StringValueCStr(descriptor_type));
|
5417
|
+
}
|
5418
|
+
cv::Ptr<cv::DescriptorMatcher> descriptorMatcher;
|
5419
|
+
try {
|
5420
|
+
descriptorMatcher = cv::DescriptorMatcher::create(StringValueCStr(matcher_type));
|
5421
|
+
}
|
5422
|
+
catch(cv::Exception& e) {
|
5423
|
+
rb_raise(rb_eArgError, "Could not create descriptor matcher by given matcher type: %s", StringValueCStr(matcher_type));
|
5424
|
+
}
|
5362
5425
|
|
5363
|
-
|
5364
|
-
|
5365
|
-
|
5366
|
-
|
5367
|
-
|
5368
|
-
|
5369
|
-
|
5370
|
-
|
5426
|
+
std::vector<cv::KeyPoint> queryKeypoints;
|
5427
|
+
std::vector<std::vector<cv::KeyPoint> > trainKeypoints;
|
5428
|
+
featureDetector->detect(queryImage, queryKeypoints);
|
5429
|
+
featureDetector->detect(trainImages, trainKeypoints);
|
5430
|
+
cv::Mat queryDescriptors;
|
5431
|
+
std::vector<cv::Mat> trainDescriptors;
|
5432
|
+
descriptorExtractor->compute(queryImage, queryKeypoints, queryDescriptors);
|
5433
|
+
descriptorExtractor->compute(trainImages, trainKeypoints, trainDescriptors);
|
5434
|
+
std::vector<cv::DMatch> matches;
|
5435
|
+
descriptorMatcher->add(trainDescriptors);
|
5436
|
+
descriptorMatcher->train();
|
5437
|
+
descriptorMatcher->match(queryDescriptors, matches);
|
5438
|
+
|
5439
|
+
for (size_t i = 0, n = matches.size(); i < n; i++) {
|
5440
|
+
VALUE match = INT2FIX(matches[i].imgIdx);
|
5441
|
+
VALUE count = rb_hash_lookup(_matches, match);
|
5442
|
+
if (NIL_P(count)) {
|
5443
|
+
count = INT2FIX(1);
|
5444
|
+
} else {
|
5445
|
+
count = INT2FIX(FIX2INT(count) + 1);
|
5446
|
+
}
|
5447
|
+
rb_hash_aset(_matches, match, count);
|
5371
5448
|
}
|
5372
|
-
rb_hash_aset(_matches, match, count);
|
5373
5449
|
}
|
5450
|
+
catch (cv::Exception& e) {
|
5451
|
+
raise_cverror(e);
|
5452
|
+
}
|
5453
|
+
|
5374
5454
|
return _matches;
|
5375
5455
|
}
|
5376
5456
|
|
@@ -5800,6 +5880,55 @@ rb_extract_surf(int argc, VALUE *argv, VALUE self)
|
|
5800
5880
|
return rb_assoc_new(_keypoints, _descriptors);
|
5801
5881
|
}
|
5802
5882
|
|
5883
|
+
|
5884
|
+
/*
|
5885
|
+
* call-seq:
|
5886
|
+
* subspace_project(w, mean) -> cvmat
|
5887
|
+
*/
|
5888
|
+
VALUE
|
5889
|
+
rb_subspace_project(VALUE self, VALUE w, VALUE mean)
|
5890
|
+
{
|
5891
|
+
VALUE projection;
|
5892
|
+
try {
|
5893
|
+
cv::Mat w_mat(CVMAT_WITH_CHECK(w));
|
5894
|
+
cv::Mat mean_mat(CVMAT_WITH_CHECK(mean));
|
5895
|
+
cv::Mat self_mat(CVMAT(self));
|
5896
|
+
cv::Mat pmat = cv::subspaceProject(w_mat, mean_mat, self_mat);
|
5897
|
+
projection = new_object(pmat.rows, pmat.cols, pmat.type());
|
5898
|
+
CvMat tmp = pmat;
|
5899
|
+
cvCopy(&tmp, CVMAT(projection));
|
5900
|
+
}
|
5901
|
+
catch (cv::Exception& e) {
|
5902
|
+
raise_cverror(e);
|
5903
|
+
}
|
5904
|
+
|
5905
|
+
return projection;
|
5906
|
+
}
|
5907
|
+
|
5908
|
+
/*
|
5909
|
+
* call-seq:
|
5910
|
+
* subspace_reconstruct(w, mean) -> cvmat
|
5911
|
+
*/
|
5912
|
+
VALUE
|
5913
|
+
rb_subspace_reconstruct(VALUE self, VALUE w, VALUE mean)
|
5914
|
+
{
|
5915
|
+
VALUE result;
|
5916
|
+
try {
|
5917
|
+
cv::Mat w_mat(CVMAT_WITH_CHECK(w));
|
5918
|
+
cv::Mat mean_mat(CVMAT_WITH_CHECK(mean));
|
5919
|
+
cv::Mat self_mat(CVMAT(self));
|
5920
|
+
cv::Mat rmat = cv::subspaceReconstruct(w_mat, mean_mat, self_mat);
|
5921
|
+
result = new_object(rmat.rows, rmat.cols, rmat.type());
|
5922
|
+
CvMat tmp = rmat;
|
5923
|
+
cvCopy(&tmp, CVMAT(result));
|
5924
|
+
}
|
5925
|
+
catch (cv::Exception& e) {
|
5926
|
+
raise_cverror(e);
|
5927
|
+
}
|
5928
|
+
|
5929
|
+
return result;
|
5930
|
+
}
|
5931
|
+
|
5803
5932
|
VALUE
|
5804
5933
|
new_object(int rows, int cols, int type)
|
5805
5934
|
{
|
data/ext/opencv/cvmat.h
CHANGED
@@ -78,7 +78,7 @@ VALUE rb_set_identity_bang(int argc, VALUE *argv, VALUE self);
|
|
78
78
|
VALUE rb_range(VALUE self, VALUE start, VALUE end);
|
79
79
|
VALUE rb_range_bang(VALUE self, VALUE start, VALUE end);
|
80
80
|
/* Transforms and Permutations */
|
81
|
-
VALUE rb_reshape(VALUE
|
81
|
+
VALUE rb_reshape(int argc, VALUE *argv, VALUE self);
|
82
82
|
VALUE rb_repeat(VALUE self, VALUE object);
|
83
83
|
VALUE rb_flip(int argc, VALUE *argv, VALUE self);
|
84
84
|
VALUE rb_flip_bang(int argc, VALUE *argv, VALUE self);
|
@@ -175,6 +175,7 @@ VALUE rb_quadrangle_sub_pix(int argc, VALUE *argv, VALUE self);
|
|
175
175
|
VALUE rb_resize(int argc, VALUE *argv, VALUE self);
|
176
176
|
VALUE rb_warp_affine(int argc, VALUE *argv, VALUE self);
|
177
177
|
VALUE rb_rotation_matrix2D(VALUE self, VALUE center, VALUE angle, VALUE scale);
|
178
|
+
VALUE rb_get_perspective_transform(VALUE self, VALUE source, VALUE dest);
|
178
179
|
VALUE rb_warp_perspective(int argc, VALUE *argv, VALUE self);
|
179
180
|
VALUE rb_find_homograpy(int argc, VALUE *argv, VALUE self);
|
180
181
|
VALUE rb_remap(int argc, VALUE *argv, VALUE self);
|
@@ -214,6 +215,9 @@ VALUE rb_dist_transform(int argc, VALUE *argv, VALUE self);
|
|
214
215
|
VALUE rb_inpaint(VALUE self, VALUE inpaint_method, VALUE mask, VALUE radius);
|
215
216
|
|
216
217
|
VALUE rb_equalize_hist(VALUE self);
|
218
|
+
|
219
|
+
VALUE rb_apply_color_map(VALUE self, VALUE colormap);
|
220
|
+
|
217
221
|
/* Matching*/
|
218
222
|
VALUE rb_match_template(int argc, VALUE *argv, VALUE self);
|
219
223
|
VALUE rb_match_shapes(int argc, VALUE *argv, VALUE self);
|
@@ -236,6 +240,9 @@ VALUE rb_compute_correspond_epilines(VALUE klass, VALUE points, VALUE which_imag
|
|
236
240
|
/* Feature detection and description */
|
237
241
|
VALUE rb_extract_surf(int argc, VALUE *argv, VALUE self);
|
238
242
|
|
243
|
+
VALUE rb_subspace_project(VALUE self, VALUE w, VALUE mean);
|
244
|
+
VALUE rb_subspace_reconstruct(VALUE self, VALUE w, VALUE mean);
|
245
|
+
|
239
246
|
// HighGUI function
|
240
247
|
VALUE rb_save_image(int argc, VALUE *argv, VALUE self);
|
241
248
|
|