我尝试使用功能fitLine()的OpenCV 2.1,但它需要转换我vector<Point>垫上.我怎样才能做到这一点?
vector<Point> line_points;
Vec4f line;
fitLine(line_points, line, CV_DIST_L2, 0.0, 0.01, 0.01);
Run Code Online (Sandbox Code Playgroud) 使用OpenCV 2.3的新API,我无法将值分配给循环内的Mat数组(或说图像).这是我正在使用的代码片段;
int paddedHeight = 256 + 2*padSize;
int paddedWidth = 256 + 2*padSize;
int n = 266; // padded height or width
cv::Mat fx = cv::Mat(paddedHeight,paddedWidth,CV_64FC1);
cv::Mat fy = cv::Mat(paddedHeight,paddedWidth,CV_64FC1);
float value = -n/2.0f;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
fx.at<cv::Vec2d>(i,j) = value++;
value = -n/2.0f;
}
meshElement = -n/2.0f;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
fy.at<cv::Vec2d>(i,j) = value;
value++;
}
Run Code Online (Sandbox Code Playgroud)
现在在第一个循环中,一旦j = 133,我得到一个异常,这似乎与图像的深度有关,我无法弄清楚我在这里做错了什么.
请指教!谢谢!

有一种非常简单的方法可以从向量构造Mat ...只需执行以下操作:
vector<int> myVector;
Mat myMatFromVector(myVector,true); //the boolean is to define if you want to copy the data
Run Code Online (Sandbox Code Playgroud)
这个构造函数的问题是每个向量的元素将被放置在Matrix的每一行中.我想要的是我的矢量的每个元素都放在矩阵的每一列中.
As is:
vector<int> = [1,2,3,4]
Matrix = [1;2;3;4]
I want:
vector<int> = [1,2,3,4]
Matrix = [1,2,3,4]
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用c ++ opencv将矢量转换为(128*128)矩阵这是代码
Mat image = imread("1.jpg", 0);
vector<double> vec ImgVec[i].assign(image.datastart, image.dataend);
vector<double> avgFace = calAvgFace(vec);
Mat img=avgFace;
Run Code Online (Sandbox Code Playgroud)
代码的最后一行不正确,但它只是一个例子.