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)
-See http://opencv.willowgarage.com/wiki/Android
+See http://code.opencv.org/projects/opencv/wiki/OpenCV4Android
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`,
};
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();
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++ )
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_);
}
}
}
- func( src, dst, xofs, k );
+ func( src, dst, xofs, k ,scale_y);
return;
}
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;
#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 {
#ifndef __OPENCV_STITCHING_WARPER_CREATORS_HPP__
#define __OPENCV_STITCHING_WARPER_CREATORS_HPP__
-#include "detail/warpers.hpp"
+#include "opencv2/stitching/detail/warpers.hpp"
namespace cv {
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))","")
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 };
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
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
--- /dev/null
+'''\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