Merged the trunk r8547:8574, r8587
authorAndrey Kamaev <no@email>
Fri, 15 Jun 2012 08:36:35 +0000 (08:36 +0000)
committerAndrey Kamaev <no@email>
Fri, 15 Jun 2012 08:36:35 +0000 (08:36 +0000)
12 files changed:
CMakeLists.txt
android/README.android
modules/imgproc/doc/motion_analysis_and_object_tracking.rst
modules/imgproc/src/imgwarp.cpp
modules/ml/src/boost.cpp
modules/stitching/include/opencv2/stitching/stitcher.hpp
modules/stitching/include/opencv2/stitching/warpers.hpp
samples/android/tutorial-4-mixed/jni/Android.mk
samples/cpp/tutorial_code/Histograms_Matching/compareHist_Demo.cpp
samples/python2/common.py
samples/python2/digits.png [new file with mode: 0644]
samples/python2/digits.py [new file with mode: 0644]

index 0c9518b..bb6ba19 100644 (file)
@@ -318,7 +318,7 @@ if(UNIX)
     CHECK_INCLUDE_FILE(pthread.h HAVE_LIBPTHREAD)
     if(ANDROID)
       set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} dl m log)
-    elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
+    elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD|NetBSD|DragonFly")
       set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} m pthread)
     else()
       set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} dl m pthread rt)
index b9c6880..46207b0 100644 (file)
@@ -1 +1 @@
-See http://opencv.willowgarage.com/wiki/Android
+See http://code.opencv.org/projects/opencv/wiki/OpenCV4Android
index 34dae1e..8a4d050 100644 (file)
@@ -161,34 +161,34 @@ Return value: detected phase shift (sub-pixel) between the two arrays.
 
 The function performs the following equations
 
-*
-    First it applies a Hanning window (see http://en.wikipedia.org/wiki/Hann\_function) to each image to remove possible edge effects. This window is cached until the array size changes to speed up processing time.
+* First it applies a Hanning window (see http://en.wikipedia.org/wiki/Hann\_function) to each image to remove possible edge effects. This window is cached until the array size changes to speed up processing time.
 
-*
-    Next it computes the forward DFTs of each source array:
-    .. math::
+* Next it computes the forward DFTs of each source array:
+
+     .. math::
 
         \mathbf{G}_a = \mathcal{F}\{src_1\}, \; \mathbf{G}_b = \mathcal{F}\{src_2\}
 
-    where
-    :math:`\mathcal{F}` is the forward DFT.
+  where
+  :math:`\mathcal{F}` is the forward DFT.
+
+* It then computes the cross-power spectrum of each frequency domain array:
 
-*
-    It then computes the cross-power spectrum of each frequency domain array:
     .. math::
 
-        R = \frac{ \mathbf{G}_a \mathbf{G}_b^*}{|\mathbf{G}_a \mathbf{G}_b^*|}
+          R = \frac{ \mathbf{G}_a \mathbf{G}_b^*}{|\mathbf{G}_a \mathbf{G}_b^*|}
+
+* Next the cross-correlation is converted back into the time domain via the inverse DFT:
 
-*
-    Next the cross-correlation is converted back into the time domain via the inverse DFT:
     .. math::
 
-        r = \mathcal{F}^{-1}\{R\}
-*
-    Finally, it computes the peak location and computes a 5x5 weighted centroid around the peak to achieve sub-pixel accuracy.
+          r = \mathcal{F}^{-1}\{R\}
+
+* Finally, it computes the peak location and computes a 5x5 weighted centroid around the peak to achieve sub-pixel accuracy.
+
     .. math::
 
-       (\Delta x, \Delta y) = \texttt{weighted_centroid}\{\arg \max_{(x, y)}\{r\}\}
+         (\Delta x, \Delta y) = \texttt{weightedCentroid} \{\arg \max_{(x, y)}\{r\}\}
 
 .. seealso::
     :ocv:func:`dft`,
index 0962af7..88d1196 100644 (file)
@@ -1207,7 +1207,7 @@ struct DecimateAlpha
 };
 
 template<typename T, typename WT>
-static void resizeArea_( const Mat& src, Mat& dst, const DecimateAlpha* xofs, int xofs_count )
+static void resizeArea_( const Mat& src, Mat& dst, const DecimateAlpha* xofs, int xofs_count, double scale_y_)
 {
     Size ssize = src.size(), dsize = dst.size();
     int cn = src.channels();
@@ -1215,7 +1215,7 @@ static void resizeArea_( const Mat& src, Mat& dst, const DecimateAlpha* xofs, in
     AutoBuffer<WT> _buffer(dsize.width*2);
     WT *buf = _buffer, *sum = buf + dsize.width;
     int k, sy, dx, cur_dy = 0;
-    WT scale_y = (WT)ssize.height/dsize.height;
+    WT scale_y = (WT)scale_y_;
 
     CV_Assert( cn <= 4 );
     for( dx = 0; dx < dsize.width; dx++ )
@@ -1315,7 +1315,7 @@ typedef void (*ResizeAreaFastFunc)( const Mat& src, Mat& dst,
                                     int scale_x, int scale_y );
 
 typedef void (*ResizeAreaFunc)( const Mat& src, Mat& dst,
-                                const DecimateAlpha* xofs, int xofs_count );
+                                const DecimateAlpha* xofs, int xofs_count, double scale_y_);
 
 }
 
@@ -1532,7 +1532,7 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize,
             }
         }
 
-        func( src, dst, xofs, k );
+        func( src, dst, xofs, k ,scale_y);
         return;
     }
 
index 3d938c7..ff7120c 100644 (file)
@@ -1132,7 +1132,7 @@ CvBoost::update_weights( CvBoostTree* tree )
     else
     {
         if( have_subsample )
-            _buf_size += data->buf->step*(sizeof(float)+sizeof(uchar));
+            _buf_size += data->buf->cols*(sizeof(float)+sizeof(uchar));
     }
     inn_buf.allocate(_buf_size);
     uchar* cur_buf_pos = (uchar*)inn_buf;
index 352f238..aab2cca 100644 (file)
 
 #include "opencv2/core/core.hpp"
 #include "opencv2/features2d/features2d.hpp"
-#include "warpers.hpp"
-#include "detail/matchers.hpp"
-#include "detail/motion_estimators.hpp"
-#include "detail/exposure_compensate.hpp"
-#include "detail/seam_finders.hpp"
-#include "detail/blenders.hpp"
-#include "detail/camera.hpp"
+#include "opencv2/stitching/warpers.hpp"
+#include "opencv2/stitching/detail/matchers.hpp"
+#include "opencv2/stitching/detail/motion_estimators.hpp"
+#include "opencv2/stitching/detail/exposure_compensate.hpp"
+#include "opencv2/stitching/detail/seam_finders.hpp"
+#include "opencv2/stitching/detail/blenders.hpp"
+#include "opencv2/stitching/detail/camera.hpp"
 
 namespace cv {
 
index 4c5cd59..d260a30 100644 (file)
@@ -43,7 +43,7 @@
 #ifndef __OPENCV_STITCHING_WARPER_CREATORS_HPP__
 #define __OPENCV_STITCHING_WARPER_CREATORS_HPP__
 
-#include "detail/warpers.hpp"
+#include "opencv2/stitching/detail/warpers.hpp"
 
 namespace cv {
 
index a20c246..bd06352 100644 (file)
@@ -3,6 +3,8 @@ LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
 
 OPENCV_CAMERA_MODULES:=off
+OPENCV_INSTALL_MODULES:=on
+#OPENCV_LIB_TYPE:=SHARED <- this is default
 
 include ../includeOpenCV.mk
 ifeq ("$(wildcard $(OPENCV_MK_PATH))","")
index 3bc60fe..57ba3ea 100644 (file)
@@ -44,8 +44,8 @@ int main( int argc, char** argv )
     int histSize[] = { h_bins, s_bins };
 
     // hue varies from 0 to 256, saturation from 0 to 180
-    float h_ranges[] = { 0, 256 };
-    float s_ranges[] = { 0, 180 };
+    float s_ranges[] = { 0, 256 };
+    float h_ranges[] = { 0, 180 };
 
     const float* ranges[] = { h_ranges, s_ranges };
 
index 54e23d6..0eb49b8 100644 (file)
@@ -2,6 +2,7 @@ import numpy as np
 import cv2\r
 import os\r
 from contextlib import contextmanager\r
+import itertools as it\r
 \r
 image_extensions = ['.bmp', '.jpg', '.jpeg', '.png', '.tif', '.tiff', '.pbm', '.pgm', '.ppm']\r
 \r
@@ -170,3 +171,22 @@ class RectSelector:
             return\r
         x0, y0, x1, y1 = self.drag_rect\r
         cv2.rectangle(vis, (x0, y0), (x1, y1), (0, 255, 0), 2)\r
+\r
+\r
+def grouper(n, iterable, fillvalue=None):\r
+    '''grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx'''\r
+    args = [iter(iterable)] * n\r
+    return it.izip_longest(fillvalue=fillvalue, *args)\r
+\r
+def mosaic(w, imgs):\r
+    '''Make a grid from images. \r
+\r
+    w    -- number of grid columns\r
+    imgs -- images (must have same size and format)\r
+    '''\r
+    imgs = iter(imgs)\r
+    img0 = imgs.next()\r
+    pad = np.zeros_like(img0)\r
+    imgs = it.chain([img0], imgs)\r
+    rows = grouper(w, imgs, pad)\r
+    return np.vstack(map(np.hstack, rows))\r
diff --git a/samples/python2/digits.png b/samples/python2/digits.png
new file mode 100644 (file)
index 0000000..01cdd29
Binary files /dev/null and b/samples/python2/digits.png differ
diff --git a/samples/python2/digits.py b/samples/python2/digits.py
new file mode 100644 (file)
index 0000000..f4bb0a5
--- /dev/null
@@ -0,0 +1,78 @@
+'''\r
+Neural network digit recognition sample.\r
+Usage:\r
+   digits.py\r
+\r
+   Sample loads a dataset of handwritten digits from 'digits.png'.\r
+   Then it trains a neural network classifier on it and evaluates\r
+   its classification accuracy.\r
+'''\r
+\r
+import numpy as np\r
+import cv2\r
+from common import mosaic\r
+\r
+def unroll_responses(responses, class_n):\r
+    '''[1, 0, 2, ...] -> [[0, 1, 0], [1, 0, 0], [0, 0, 1], ...]'''\r
+    sample_n = len(responses)\r
+    new_responses = np.zeros((sample_n, class_n), np.float32)\r
+    new_responses[np.arange(sample_n), responses] = 1\r
+    return new_responses\r
+    \r
+\r
+SZ = 20 # size of each digit is SZ x SZ\r
+CLASS_N = 10\r
+digits_img = cv2.imread('digits.png', 0)\r
+\r
+# prepare dataset\r
+h, w = digits_img.shape\r
+digits = [np.hsplit(row, w/SZ) for row in np.vsplit(digits_img, h/SZ)]\r
+digits = np.float32(digits).reshape(-1, SZ*SZ)\r
+N = len(digits)\r
+labels = np.repeat(np.arange(CLASS_N), N/CLASS_N)\r
+\r
+# split it onto train and test subsets\r
+shuffle = np.random.permutation(N)\r
+train_n = int(0.9*N)\r
+digits_train, digits_test = np.split(digits[shuffle], [train_n])\r
+labels_train, labels_test = np.split(labels[shuffle], [train_n])\r
+\r
+# train model\r
+model = cv2.ANN_MLP()\r
+layer_sizes = np.int32([SZ*SZ, 25, CLASS_N])\r
+model.create(layer_sizes)\r
+params = dict( term_crit = (cv2.TERM_CRITERIA_COUNT, 100, 0.01),\r
+               train_method = cv2.ANN_MLP_TRAIN_PARAMS_BACKPROP,\r
+               bp_dw_scale = 0.001,\r
+               bp_moment_scale = 0.0 )\r
+print 'training...'\r
+labels_train_unrolled = unroll_responses(labels_train, CLASS_N)\r
+model.train(digits_train, labels_train_unrolled, None, params=params)\r
+model.save('dig_nn.dat')\r
+model.load('dig_nn.dat')\r
+\r
+def evaluate(model, samples, labels):\r
+    '''Evaluates classifier preformance on a given labeled samples set.'''\r
+    ret, resp = model.predict(samples)\r
+    resp = resp.argmax(-1)\r
+    error_mask = (resp == labels)\r
+    accuracy = error_mask.mean()\r
+    return accuracy, error_mask\r
+\r
+# evaluate model\r
+train_accuracy, _ = evaluate(model, digits_train, labels_train)\r
+print 'train accuracy: ', train_accuracy\r
+test_accuracy, test_error_mask = evaluate(model, digits_test, labels_test)\r
+print 'test accuracy: ', test_accuracy\r
+\r
+# visualize test results\r
+vis = []\r
+for img, flag in zip(digits_test, test_error_mask):\r
+    img = np.uint8(img).reshape(SZ, SZ)\r
+    img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)\r
+    if not flag:\r
+        img[...,:2] = 0\r
+    vis.append(img)\r
+vis = mosaic(25, vis)\r
+cv2.imshow('test', vis)\r
+cv2.waitKey()\r