本文整理汇总了C++中Mat::dot方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat::dot方法的具体用法?C++ Mat::dot怎么用?C++ Mat::dot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat
的用法示例。
在下文中一共展示了Mat::dot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getVR
// Variance Ratio
double getVR(Mat hist1,Mat hist2)
{
Mat idx=Mat::zeros(hist1.rows,hist1.cols,CV_32FC1);
for (int i=0;i<idx.rows;++i)
{
float* r_ptr=idx.ptr<float>(i);
r_ptr[0]=(float)i;
}
double mean_idx=hist1.dot(idx);
Mat temp=idx-mean_idx;
temp=temp.mul(temp);
double variance1=hist1.dot(temp);
mean_idx=hist2.dot(idx);
temp=idx-mean_idx;
temp=temp.mul(temp);
double variance2=hist2.dot(temp);
Mat hist_mean=(hist1+hist2)*0.5;
mean_idx=hist_mean.dot(idx);
temp=idx-mean_idx;
temp=temp.mul(temp);
double variance_mean=hist_mean.dot(temp);
return variance_mean/(variance1+variance2);
}
示例2: UpdateCompetition
Mat UpdateCompetition(Mat Transformed_Templates, Mat BackwardTransform, Mat g, int r, double k, Mat TranSc,double p){
int count = Transformed_Templates.rows;
g.convertTo(g,CV_32F);
Mat subtracted_g(g.rows, g.cols, CV_64FC1);
Mat thresholded_g(g.rows, g.cols, CV_32FC1);
double Thresh_VAL = 0.1;
double MAX_VAL = 1;
Mat q(g.rows, g.cols, CV_32F);
double T_L2;
double BackwardTransform_L2;
double min, max;
if (dispsc)
cout << TranSc << endl;
for(int i=0; i<count; i++){
if (g.at<float>(0, i) == 0) {
q.at<float>(0, i) = 0;
continue;
}
Mat T = Transformed_Templates.row(i).reshape(0,r);
T.convertTo(T,CV_32FC1);
//T_L2 = norm(T, NORM_L2);
T_L2 = sum(T)[0];
//T_L2 = sum(T)[0];
//BackwardTransform_L2 = norm(BackwardTransform, NORM_L2);
BackwardTransform_L2 = sum(BackwardTransform)[0];
if (test_comp) {
imshow("T", T);
imshow("BackwardTransform", BackwardTransform);
waitKey();
}
//cout << TranSc << endl;
if(BackwardTransform_L2 !=0 && T_L2 != 0){
if (startscale)
q.at<float>(0,i) = T.dot(BackwardTransform)*((TranSc.at<float>(0,i)));
//q.at<double>(0, i) = T.dot(BackwardTransform) / T_L2;
else
q.at<float>(0, i) = T.dot(BackwardTransform);
}else{
q.at<float>(0,i) = 0;
}
if (startscale)
if (TranSc.at<float>(0,i) < 1)
p = 1.5;
}
//cout<<"q: "<<q<<endl;
minMaxLoc(q, &min, &max);
// cout<<"q_min:"<<min<<" q_max: "<<max<<endl;
Mat temp;
pow(1- q / max, p, temp);
subtract(g, k*(temp), subtracted_g) ;
//cout << "g:" << g << " subtracted_g: " << subtracted_g << endl;
subtracted_g.convertTo(subtracted_g,CV_32F);
threshold(subtracted_g, thresholded_g, Thresh_VAL, MAX_VAL, THRESH_TOZERO);
return thresholded_g;
}
示例3: ChangeSpace
void MarkerLocator::ChangeSpace(Mat& r_point)
{
double wz = r_point.dot(m_robotForward) / m_robotForward.dot(m_robotForward);
double wx = r_point.dot(m_robotSide) / m_robotSide.dot(m_robotSide);
r_point = (Mat_<double>(3, 1) << wx, 0.0, wz);
}
示例4: cal_3d_point2line_intersect
Mat cal_3d_point2line_intersect(Mat l_first_point, Mat l_second_point, Mat point) {
Mat v = l_second_point - l_first_point;
Mat w = point - l_first_point;
double c1 = w.dot(v);
double c2 = v.dot(v);
double b = c1 / c2;
return l_first_point + b * v;
}
示例5: cal_3d_point2line_distance
float cal_3d_point2line_distance(Mat l_first_point, Mat l_second_point, Mat point) {
Mat v = l_second_point - l_first_point;
Mat w = point - l_first_point;
double c1 = w.dot(v);
double c2 = v.dot(v);
double b = c1 / c2;
Mat norm = point - (l_first_point + b * v);
return norm.dot(norm);
}
示例6: CalcDistanceToFeatureLine
float CalcDistanceToFeatureLine(Mat f1, Mat f2, Mat fx)
{
Mat a = fx - f1;
Mat b = f2 - f1;
double numerator = a.dot(b);
double denominator = b.dot(b);
float muy = (float)(numerator / denominator);
Mat px = f1 + muy*(f2 - f1);
return CalcVectorMagnitude((fx - px));
}
示例7: calculateArea
double calculateArea(Mat img,int col,int row)
{
Mat A = Mat::ones(row, col, CV_8U);
return A.dot(img);
}
示例8: calcShift
float SVMSGDImpl::calcShift(InputArray _samples, InputArray _responses) const
{
float margin[2] = { std::numeric_limits<float>::max(), std::numeric_limits<float>::max() };
Mat trainSamples = _samples.getMat();
int trainSamplesCount = trainSamples.rows;
Mat trainResponses = _responses.getMat();
CV_Assert(trainResponses.type() == CV_32FC1);
for (int samplesIndex = 0; samplesIndex < trainSamplesCount; samplesIndex++)
{
Mat currentSample = trainSamples.row(samplesIndex);
float dotProduct = static_cast<float>(currentSample.dot(weights_));
bool positive = isPositive(trainResponses.at<float>(samplesIndex));
int index = positive ? 0 : 1;
float signToMul = positive ? 1.f : -1.f;
float curMargin = dotProduct * signToMul;
if (curMargin < margin[index])
{
margin[index] = curMargin;
}
}
return -(margin[0] - margin[1]) / 2.f;
}
示例9: predict
float SVMSGDImpl::predict( InputArray _samples, OutputArray _results, int ) const
{
float result = 0;
cv::Mat samples = _samples.getMat();
int nSamples = samples.rows;
cv::Mat results;
CV_Assert( samples.cols == weights_.cols && samples.type() == CV_32FC1);
if( _results.needed() )
{
_results.create( nSamples, 1, samples.type() );
results = _results.getMat();
}
else
{
CV_Assert( nSamples == 1 );
results = Mat(1, 1, CV_32FC1, &result);
}
for (int sampleIndex = 0; sampleIndex < nSamples; sampleIndex++)
{
Mat currentSample = samples.row(sampleIndex);
float criterion = static_cast<float>(currentSample.dot(weights_)) + shift_;
results.at<float>(sampleIndex) = (criterion >= 0) ? 1.f : -1.f;
}
return result;
}
示例10: copyMakeBorder
/* Convolutions */
Mat Image::convolution1D1C(Mat &input, Mat &mask, bool reflected)
{
// Expand the matrix
Mat expanded, copy_input;
int borderType = BORDER_CONSTANT;
int offset = (mask.cols - 1) / 2;
if (reflected)
borderType = BORDER_REFLECT;
copyMakeBorder(input,expanded,0,0,offset,offset,borderType,0);
// Convolution!
Mat ROI;
Mat output = Mat::zeros(1, input.cols, CV_32FC1);
expanded.convertTo(expanded,CV_32FC1);
for (int i = 0; i < input.cols; i++) // Index are OK
{
ROI = Mat(expanded, Rect(i,0,mask.cols,1));
output.at<float>(Point(i,0)) = ROI.dot(mask);
}
return output;
}
示例11: apply5Filter
void apply5Filter(Mat source, Mat filter, Mat result){
//dims of source mat
int h = source.rows;
int w = source.cols;
Mat temp;
double dot;
//allocate space for result mat
//incase result and source are same vector, we don't overwrite result
Mat tempResult(h, w, CV_64F);
//add border to source image for filtering
copyMakeBorder(source, temp, 2, 2, 2, 2, BORDER_REPLICATE);
//filter source mat and store in result mat pixel by pixel
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
dot = filter.dot(temp.rowRange(i, i+5).colRange(j, j+5));
tempResult.at<double>(i, j) = dot;
}
}
//overwrite result
tempResult.copyTo(result);
}
示例12: F
//==============================================================================
void
patch_model::
train(const vector<Mat> &images,
const Size psize,
const float var,
const float lambda,
const float mu_init,
const int nsamples,
const bool visi)
{
int N = images.size(),n = psize.width*psize.height;
//compute desired response map
Size wsize = images[0].size();
if((wsize.width < psize.width) || (wsize.height < psize.height)){
cerr << "Invalid image size < patch size!" << endl; throw std::exception();
}
int dx = wsize.width-psize.width,dy = wsize.height-psize.height;
Mat F(dy,dx,CV_32F);
for(int y = 0; y < dy; y++){ float vy = (dy-1)/2 - y;
for(int x = 0; x < dx; x++){ float vx = (dx-1)/2 - x;
F.fl(y,x) = exp(-0.5*(vx*vx+vy*vy)/var);
}
}
normalize(F,F,0,1,NORM_MINMAX);
//allocate memory
Mat I(wsize.height,wsize.width,CV_32F);
Mat dP(psize.height,psize.width,CV_32F);
Mat O = Mat::ones(psize.height,psize.width,CV_32F)/n;
P = Mat::zeros(psize.height,psize.width,CV_32F);
//optimise using stochastic gradient descent
RNG rn(getTickCount()); double mu=mu_init,step=pow(1e-8/mu_init,1.0/nsamples);
for(int sample = 0; sample < nsamples; sample++){ int i = rn.uniform(0,N);
I = this->convert_image(images[i]); dP = 0.0;
for(int y = 0; y < dy; y++){
for(int x = 0; x < dx; x++){
Mat Wi = I(Rect(x,y,psize.width,psize.height)).clone();
Wi -= Wi.dot(O); normalize(Wi,Wi);
dP += (F.fl(y,x) - P.dot(Wi))*Wi;
}
}
P += mu*(dP - lambda*P); mu *= step;
if(visi){
Mat R; matchTemplate(I,P,R,CV_TM_CCOEFF_NORMED);
Mat PP; normalize(P,PP,0,1,NORM_MINMAX);
normalize(dP,dP,0,1,NORM_MINMAX);
normalize(R,R,0,1,NORM_MINMAX);
imshow("P",PP); imshow("dP",dP); imshow("R",R);
if(waitKey(10) == 27)break;
}
}return;
}
示例13: project_onto_jacobian_ECC
static void project_onto_jacobian_ECC(const Mat& src1, const Mat& src2, Mat& dst)
{
/* this functions is used for two types of projections. If src1.cols ==src.cols
it does a blockwise multiplication (like in the outer product of vectors)
of the blocks in matrices src1 and src2 and dst
has size (number_of_blcks x number_of_blocks), otherwise dst is a vector of size
(number_of_blocks x 1) since src2 is "multiplied"(dot) with each block of src1.
The number_of_blocks is equal to the number of parameters we are lloking for
(i.e. rtanslation:2, euclidean: 3, affine: 6, homography: 8)
*/
CV_Assert(src1.rows == src2.rows);
CV_Assert((src1.cols % src2.cols) == 0);
int w;
float* dstPtr = dst.ptr<float>(0);
if (src1.cols !=src2.cols){//dst.cols==1
w = src2.cols;
for (int i=0; i<dst.rows; i++){
dstPtr[i] = (float) src2.dot(src1.colRange(i*w,(i+1)*w));
}
}
else {
CV_Assert(dst.cols == dst.rows); //dst is square (and symmetric)
w = src2.cols/dst.cols;
Mat mat;
for (int i=0; i<dst.rows; i++){
mat = Mat(src1.colRange(i*w, (i+1)*w));
dstPtr[i*(dst.rows+1)] = (float) pow(norm(mat),2); //diagonal elements
for (int j=i+1; j<dst.cols; j++){ //j starts from i+1
dstPtr[i*dst.cols+j] = (float) mat.dot(src2.colRange(j*w, (j+1)*w));
dstPtr[j*dst.cols+i] = dstPtr[i*dst.cols+j]; //due to symmetry
}
}
}
}
示例14: setXYZ
/*
void point3d2Mat(const Point3d& src, Mat& dest)
{
dest.create(3,1,CV_64F);
dest.at<double>(0,0)=src.x;
dest.at<double>(1,0)=src.y;
dest.at<double>(2,0)=src.z;
}
void setXYZ(Mat& in, double&x, double&y, double&z)
{
x=in.at<double>(0,0);
y=in.at<double>(1,0);
z=in.at<double>(2,0);
// cout<<format("set XYZ: %.04f %.04f %.04f\n",x,y,z);
}
void lookatBF(const Point3d& from, const Point3d& to, Mat& destR)
{
double x,y,z;
Mat fromMat;
Mat toMat;
point3d2Mat(from,fromMat);
point3d2Mat(to,toMat);
Mat fromtoMat;
add(toMat,fromMat,fromtoMat,Mat(),CV_64F);
double ndiv = 1.0/norm(fromtoMat);
fromtoMat*=ndiv;
setXYZ(fromtoMat,x,y,z);
destR = Mat::eye(3,3,CV_64F);
double yaw =-z/abs(z)*asin(y/sqrt(y*y+z*z))/CV_PI*180.0;
rotYaw(destR,destR,yaw);
Mat RfromtoMat = destR*fromtoMat;
setXYZ(RfromtoMat,x,y,z);
double pitch =z/abs(z)*asin(x/sqrt(x*x+z*z))/CV_PI*180.0;
rotPitch(destR,destR,pitch);
}
*/
void lookat(const Point3d& from, const Point3d& to, Mat& destR)
{
Mat destMat = Mat(Point3d(0.0, 0.0, 1.0));
Mat srcMat = Mat(from + to);
srcMat = srcMat / norm(srcMat);
Mat rotaxis = srcMat.cross(destMat);
double angle = acos(srcMat.dot(destMat));
//normalize cross product and multiply rotation angle
rotaxis = rotaxis / norm(rotaxis)*angle;
Rodrigues(rotaxis, destR);
}
示例15: TVectToRangeBaring
void MarkerLocator::TVectToRangeBaring(Mat r_tVec, double& rr_range, double& rr_bearing)
{
// Get the vector relative to the robot rather than the camera
subtract(r_tVec, m_robotLoc, r_tVec);
// Start by projecting our transform vector onto the robot's plane
ChangeSpace(r_tVec);
// Range is easy
rr_range = sqrt(r_tVec.dot(r_tVec));
rr_bearing = atan(r_tVec.at<double>(0, 0)/r_tVec.at<double>(2, 0));
}