C++ Visual Studio 2015错误C4996';标准::_Copy_impl';:带有可能不安全参数的函数调用
我编写了这个模板类: .hpp:C++ Visual Studio 2015错误C4996';标准::_Copy_impl';:带有可能不安全参数的函数调用,c++,opencv,c++11,visual-studio-2015,C++,Opencv,C++11,Visual Studio 2015,我编写了这个模板类: .hpp: 感谢您的帮助。我按照@DanMašek在评论中建议的说明解决了问题 我添加了头,然后使用类stdext::checked\u array\u迭代器。结果是这样的: double * r0_ptr = m_matrix.ptr<double>(0); std::copy(temp_v1.begin(), temp_v1.end(), stdext::checked_array_iterator<double *>(r0_pt
感谢您的帮助。我按照@DanMašek在评论中建议的说明解决了问题 我添加了头
,然后使用类stdext::checked\u array\u迭代器
。结果是这样的:
double * r0_ptr = m_matrix.ptr<double>(0);
std::copy(temp_v1.begin(), temp_v1.end(), stdext::checked_array_iterator<double *>(r0_ptr, m_matrix.cols));
double*r0_ptr=m_matrix.ptr(0);
std::copy(temp_v1.begin()、temp_v1.end()、stdext::checked_array_迭代器(r0_ptr、m_matrix.cols));
如果要使用
中的内容,则应包含该标题。试试看,看看会发生什么。问题是您正在将普通指针作为输出迭代器传递。请注意,解决方案(和问题)都是针对MSV的。谢谢@DanMašek。在你发表文章之后,我已经解决了这个问题。
#include "stdafx.h"
#include "bivariateGaussianPDF_lib.h"
#include <iterator>
template<class T, class N>
BivariateGaussianPDF<T, N>::BivariateGaussianPDF(const std::vector<T>& i_v1,
const std::vector<N>& i_v2)
:m_pdf(i_v1.size())
{
std::vector<double> temp_v1(std::begin(i_v1), std::end(i_v1));
std::vector<double> temp_v2(std::begin(i_v2), std::end(i_v2));
m_matrix.create(2, i_v1.size(), CV_64F);
double * r0_ptr = m_matrix.ptr<double>(0);
double * r1_ptr = m_matrix.ptr<double>(1);
std::copy(temp_v1.begin(), temp_v1.end(), r0_ptr);
std::copy(temp_v2.begin(), temp_v2.end(), r1_ptr);
}
template<class T, class N>
BivariateGaussianPDF<T, N>::~BivariateGaussianPDF()
{
m_matrix.release();
}
template<class T, class N>
void BivariateGaussianPDF<T, N>::compute()
{
cv::Mat row_mean, cov, inverseCov, temp_pdf;
// compute covariance matrix
cv::calcCovarMatrix(m_matrix, cov, row_mean, CV_COVAR_ROWS | CV_COVAR_NORMAL);
// scale covariance matrix
cov = cov / (m_matrix.cols - 1);
// inverse of covariance matrix
inverseCov = cov.inv();
// determinant of covariance matrix
const double det = cv::determinant(cov);
// X = [x1; x2 ... ; xN] --> [x1 - mu1; x2 - mu2; ... ; xN - muN ]
cv::subtract(m_matrix.row(0), row_mean.row(0), m_matrix.row(0));
cv::subtract(m_matrix.row(1), row_mean.row(1), m_matrix.row(1));
// (inv*X).*X
cv::reduce((inverseCov*m_matrix).mul(m_matrix), temp_pdf, 0, CV_REDUCE_SUM);
temp_pdf = -0.5*temp_pdf;
cv::exp(temp_pdf, temp_pdf);
// bivariate gaussian pdf
temp_pdf = (0.5 / (M_PI*std::sqrt(det)))*temp_pdf;
const double * d_ptr = temp_pdf.ptr<double>(0);
std::copy(d_ptr, d_ptr + temp_pdf.cols, m_pdf.begin());
}
std::copy(temp_v1.begin(), temp_v1.end(), r0_ptr);
std::copy(temp_v2.begin(), temp_v2.end(), r1_ptr);
double * r0_ptr = m_matrix.ptr<double>(0);
std::copy(temp_v1.begin(), temp_v1.end(), stdext::checked_array_iterator<double *>(r0_ptr, m_matrix.cols));