我正在尝试创建一个矩阵,其中只有一列来自另一个矩阵,当然还有复制数据。
void redim( Mat in , Mat &out) {
for (int l=0 ; l < in.rows*in.cols ; l++){
for(int j=0; j< in.rows ; j++){
for(int i=0 ; i < in.cols; i++){
out.at <float> (l,0)= in.at <float> (j,i);
}
}
}
}
int main(){
Mat It3;
It3 = (Mat_<double>(2,3) << 0,4,6,7,8,9);
Mat S= Mat :: zeros ( It3.rows* It3.cols , 1, CV_32FC1) ;
redim(It3,S);
waitKey();
}
但我得到了矩阵S=[0;0;0;0;0;0]
。
答案 0 :(得分:1)
double
和for
作为数据类型。选一个!for
循环没有任何意义。你可以:
toSingleColumn1
循环,如for
toSingleColumn2
循环,但使用索引,如cv::reshape
toSingleColumn3
,与b1
请参阅下面的代码。 b2
,b3
和#include <opencv2\opencv.hpp>
using namespace cv;
// Use two for loops, with coordinates
void toSingleColumn1(const Mat1f& src, Mat1f& dst)
{
int N = src.rows * src.cols;
dst = Mat1f(N, 1);
int i=0;
for (int r = 0; r < src.rows; ++r) {
for (int c = 0; c < src.cols; ++c) {
dst(i++, 0) = src(r, c);
}
}
}
// Use a single for loop, with indices
void toSingleColumn2(const Mat1f& src, Mat1f& dst)
{
int N = src.rows * src.cols;
dst = Mat1f(N, 1);
for (int i = 0; i < N; ++i) {
dst(i) = src(i);
}
}
// Use cv::reshape
void toSingleColumn3(const Mat& src, Mat& dst)
{
// The 'clone()' is needed to deep copy the data
dst = src.reshape(src.channels(), src.rows*src.cols).clone();
}
int main()
{
Mat1f a = (Mat1f(2,3) << 0.f, 4.f, 6.f, 7.f, 8.f, 9.f);
Mat1f b1, b2, b3;
toSingleColumn1(a, b1);
toSingleColumn2(a, b2);
toSingleColumn3(a, b3);
return 0;
}
将是平等的:
function helloWorld() {
var mydoc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication().setTitle('Your Title');
var helloWorldLabel = app.createLabel('My first Google Script UI');
app.add(helloWorldLabel);
mydoc.show(app);
}