如何输出矩阵OpenCV的行和列的大小
How to output size of rows and columns of matrixOpenCV
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/core/core.hpp>
#include "cv.h"
#include "highgui.h"
#include <stdlib.h>
#include <iostream>
#include <fstream>
using namespace cv;
using namespace std;
int main()
{
Mat image = imread("cupcake.jpg");
int rows=image.rows;
cout<< rows<< endl;
int cols=image.cols;
cout<< cols<< endl;
Point2f src_point[] = {Point2f(0,0),Point2f(cols-1,0),Point2f(0, rows-1)};
cout << src_point[0].rows;
cout << src_point[0].cols;
*/I have tried src_point.Size. (says Size is not a member of cv::Point2f) */
}
我正在尝试为行和列显示输入手动网格。在第一个 cout 中,我得到了显示的数量和行数,但是在 src_point 的第二个 cout 中,我无法显示新矩阵的行数和列数。
我四处搜索,偶然发现了一些代码,这些代码将通过向像素值分配指针来输出像素值。
我需要的是获取新 src_point
的行数和列数
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat image = imread("/home/winowa/Desktop/Intern101/cupcake.jpg");
int rows = image.rows;
int cols =image.cols;
cout<< "==============ImageRows&Cols"<<endl;
cout<<image.rows<<endl;
cout<<image.cols<<endl;
cout<<image.type()<<endl;
Mat src_points;
cout<< "==============src_point"<<endl;
src_points.create(498, 450, CV_32FC1);
cout << src_points.rows <<endl;
cout << src_points.cols <<endl;
cout << src_points.type() <<endl;
Point2f srcPoint[3];
Point2f dstPoint[3];
//srcPoint2[20] = Point2f(0,0),(image.cols -1,0),(0,image,rows-1);
srcPoint[0] = Point2f(0,0);
srcPoint[1] = Point2f(image.cols -1,0);
srcPoint[2] = Point2f(0,image.rows -1);
cout<< "==============src_point Point2f"<<endl;
//cout<< srcPoint[0][1][2] << endl;
cout<< srcPoint[0] << endl;
cout<< srcPoint[1] << endl;
cout<< srcPoint[2] << endl;
cout<< "==============dst_point"<<endl;
Mat dst_points;
dst_points.create(498,450,CV_32FC1);
cout << dst_points.rows <<endl;
cout << dst_points.cols <<endl;
cout << dst_points.type() <<endl;
dstPoint[0] = Point2f(image.cols*0.0,image.rows*0.33);
dstPoint[1] = Point2f(image.cols*0.85,image.rows*0.25);
dstPoint[2] = Point2f(image.cols*0.15,image.rows*0.7);
cout<< "==============dst_point Point2f"<<endl;
cout<< dstPoint[0] << endl;
cout<< dstPoint[1] << endl;
cout<< dstPoint[2] << endl;
cout<< "==============trasform_matrix"<<endl;
Mat transform_matrix = getAffineTransform(srcPoint,dstPoint);
cout << transform_matrix << endl;
cout<< "==============destination"<<endl;
warpAffine(image, image, transform_matrix ,Size(image.cols,image.rows),INTER_LINEAR, BORDER_CONSTANT);
cout << "#####destination#####" << endl;
cout << warpAffine << endl;
imshow("WarpAffine image",image);
waitKey(0);
Point2f center;
center = Point2f(image.cols/2 , image.rows/2);
cout << "Center Col"<< endl;
cout << center << endl;
//cout << center[1] << "Center Row"<< endl;
double angle = -90.0 ;
double scale = 0.5;
Mat rotation_matrix = getRotationMatrix2D(center,angle,scale);
warpAffine(image , image , rotation_matrix, Size(image.cols,image.rows));
cout << warpAffine << endl;
imshow("WarpAffine2",image);
waitKey(0);
//return ;
}
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/core/core.hpp>
#include "cv.h"
#include "highgui.h"
#include <stdlib.h>
#include <iostream>
#include <fstream>
using namespace cv;
using namespace std;
int main()
{
Mat image = imread("cupcake.jpg");
int rows=image.rows;
cout<< rows<< endl;
int cols=image.cols;
cout<< cols<< endl;
Point2f src_point[] = {Point2f(0,0),Point2f(cols-1,0),Point2f(0, rows-1)};
cout << src_point[0].rows;
cout << src_point[0].cols;
*/I have tried src_point.Size. (says Size is not a member of cv::Point2f) */
}
我正在尝试为行和列显示输入手动网格。在第一个 cout 中,我得到了显示的数量和行数,但是在 src_point 的第二个 cout 中,我无法显示新矩阵的行数和列数。
我四处搜索,偶然发现了一些代码,这些代码将通过向像素值分配指针来输出像素值。
我需要的是获取新 src_point
的行数和列数#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat image = imread("/home/winowa/Desktop/Intern101/cupcake.jpg");
int rows = image.rows;
int cols =image.cols;
cout<< "==============ImageRows&Cols"<<endl;
cout<<image.rows<<endl;
cout<<image.cols<<endl;
cout<<image.type()<<endl;
Mat src_points;
cout<< "==============src_point"<<endl;
src_points.create(498, 450, CV_32FC1);
cout << src_points.rows <<endl;
cout << src_points.cols <<endl;
cout << src_points.type() <<endl;
Point2f srcPoint[3];
Point2f dstPoint[3];
//srcPoint2[20] = Point2f(0,0),(image.cols -1,0),(0,image,rows-1);
srcPoint[0] = Point2f(0,0);
srcPoint[1] = Point2f(image.cols -1,0);
srcPoint[2] = Point2f(0,image.rows -1);
cout<< "==============src_point Point2f"<<endl;
//cout<< srcPoint[0][1][2] << endl;
cout<< srcPoint[0] << endl;
cout<< srcPoint[1] << endl;
cout<< srcPoint[2] << endl;
cout<< "==============dst_point"<<endl;
Mat dst_points;
dst_points.create(498,450,CV_32FC1);
cout << dst_points.rows <<endl;
cout << dst_points.cols <<endl;
cout << dst_points.type() <<endl;
dstPoint[0] = Point2f(image.cols*0.0,image.rows*0.33);
dstPoint[1] = Point2f(image.cols*0.85,image.rows*0.25);
dstPoint[2] = Point2f(image.cols*0.15,image.rows*0.7);
cout<< "==============dst_point Point2f"<<endl;
cout<< dstPoint[0] << endl;
cout<< dstPoint[1] << endl;
cout<< dstPoint[2] << endl;
cout<< "==============trasform_matrix"<<endl;
Mat transform_matrix = getAffineTransform(srcPoint,dstPoint);
cout << transform_matrix << endl;
cout<< "==============destination"<<endl;
warpAffine(image, image, transform_matrix ,Size(image.cols,image.rows),INTER_LINEAR, BORDER_CONSTANT);
cout << "#####destination#####" << endl;
cout << warpAffine << endl;
imshow("WarpAffine image",image);
waitKey(0);
Point2f center;
center = Point2f(image.cols/2 , image.rows/2);
cout << "Center Col"<< endl;
cout << center << endl;
//cout << center[1] << "Center Row"<< endl;
double angle = -90.0 ;
double scale = 0.5;
Mat rotation_matrix = getRotationMatrix2D(center,angle,scale);
warpAffine(image , image , rotation_matrix, Size(image.cols,image.rows));
cout << warpAffine << endl;
imshow("WarpAffine2",image);
waitKey(0);
//return ;
}