cv::Mat 图像在用 int 与像素值相乘时以退出代码 11 结束
The cv::Mat image finished with exit code 11 when multiply with pixel value with int
我正在尝试将图像的索引与图像像素值强度乘以两个 for 循环。但有时代码会在某个循环后因“完成退出代码 11”错误而提前中断。
PS,我用 Mac 和 Clion IDE,谁能帮帮我!!!
#include <iostream>
using namespace std;
#include <cmath>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/opencv.hpp>
#include <Eigen/Geometry>
int main(int argc,char** argv){
vector<cv::Point2d> Orientation(vector<cv::KeyPoint>& ,cv::Mat & );
std::string Img_dir="/Users/mars_zhang/Downloads/A/1.png";
cv::Mat ImgCOLOR,Img,Imgout,Test;
Img=cv::imread(Img_dir,0);
std::vector<cv::KeyPoint> Keypoints;
cv::Ptr<cv::FastFeatureDetector> Feature_Detector=cv::FastFeatureDetector::create(160) ;
Feature_Detector->detect(Img,Keypoints);
cv::drawKeypoints(Img,Keypoints,Imgout);
std::cout<< Img.size<<std::endl;
vector<cv::Point2d> Coordination;
Coordination=Orientation(Keypoints,Img);
cout<< Coordination[0]<<endl;
cout<<"The Img type is = " << Img.type() << endl;
}
vector<cv::Point2d> Orientation(vector<cv::KeyPoint> &Keypoints,cv::Mat & Img)
{
int Xbound,Ybound,X,Y;
Ybound = Img.rows - 8;
Xbound = Img.cols - 8;
vector<cv::Point2d> Coordination;
cout<<"Find "<< Keypoints.size()<<" Keypoints"<<endl;
for (auto &kp :Keypoints){
X = kp.pt.x,
Y = kp.pt.y;
cv::Point Point;
if ((8 < X < Xbound) & (8 < Y < Ybound)) {
int m10 = 0, m01 = 0, m00 = 0 ,pixel;
for (int x_idx = X - 7; x_idx < X + 7; x_idx++)
{
for (int y_idx = Y - 7; y_idx < Y + 7; y_idx++)
{
pixel=(int)Img.at<uchar>(x_idx, y_idx);
cout<<"The pixel at "<<x_idx<<" "<<y_idx<<"==="<<pixel<<endl;
Point.x += x_idx * pixel;
Point.y += y_idx * pixel;
m00 += pixel;
}
}
Coordination.push_back(Point/m00);
}
}
return Coordination;
}
int X=10;
int Xbound=2;
std::cout << (8 < X < Xbound) << "!\n";
会给你1个。
(8 < 10)=真=1
和 1 < 2
不要这样组合条件,使用 (8 < X && X < Xbound)。
除了之外,下面的if语句还有一个问题
if ((8 < X < Xbound) & (8 < Y < Ybound))
and 运算符是 &&
。 &
是另一种运算符,我很确定你不想在这里使用它...
我正在尝试将图像的索引与图像像素值强度乘以两个 for 循环。但有时代码会在某个循环后因“完成退出代码 11”错误而提前中断。 PS,我用 Mac 和 Clion IDE,谁能帮帮我!!!
#include <iostream>
using namespace std;
#include <cmath>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/opencv.hpp>
#include <Eigen/Geometry>
int main(int argc,char** argv){
vector<cv::Point2d> Orientation(vector<cv::KeyPoint>& ,cv::Mat & );
std::string Img_dir="/Users/mars_zhang/Downloads/A/1.png";
cv::Mat ImgCOLOR,Img,Imgout,Test;
Img=cv::imread(Img_dir,0);
std::vector<cv::KeyPoint> Keypoints;
cv::Ptr<cv::FastFeatureDetector> Feature_Detector=cv::FastFeatureDetector::create(160) ;
Feature_Detector->detect(Img,Keypoints);
cv::drawKeypoints(Img,Keypoints,Imgout);
std::cout<< Img.size<<std::endl;
vector<cv::Point2d> Coordination;
Coordination=Orientation(Keypoints,Img);
cout<< Coordination[0]<<endl;
cout<<"The Img type is = " << Img.type() << endl;
}
vector<cv::Point2d> Orientation(vector<cv::KeyPoint> &Keypoints,cv::Mat & Img)
{
int Xbound,Ybound,X,Y;
Ybound = Img.rows - 8;
Xbound = Img.cols - 8;
vector<cv::Point2d> Coordination;
cout<<"Find "<< Keypoints.size()<<" Keypoints"<<endl;
for (auto &kp :Keypoints){
X = kp.pt.x,
Y = kp.pt.y;
cv::Point Point;
if ((8 < X < Xbound) & (8 < Y < Ybound)) {
int m10 = 0, m01 = 0, m00 = 0 ,pixel;
for (int x_idx = X - 7; x_idx < X + 7; x_idx++)
{
for (int y_idx = Y - 7; y_idx < Y + 7; y_idx++)
{
pixel=(int)Img.at<uchar>(x_idx, y_idx);
cout<<"The pixel at "<<x_idx<<" "<<y_idx<<"==="<<pixel<<endl;
Point.x += x_idx * pixel;
Point.y += y_idx * pixel;
m00 += pixel;
}
}
Coordination.push_back(Point/m00);
}
}
return Coordination;
}
int X=10;
int Xbound=2;
std::cout << (8 < X < Xbound) << "!\n";
会给你1个。
(8 < 10)=真=1 和 1 < 2
不要这样组合条件,使用 (8 < X && X < Xbound)。
除了
if ((8 < X < Xbound) & (8 < Y < Ybound))
and 运算符是 &&
。 &
是另一种运算符,我很确定你不想在这里使用它...