我试图在嵌套内执行某些代码之前检查某些条件是否为真-如果只测试了第一个条件,其余的则被忽略了……请问我怎么了?。
int main()
{
cout << "Enter your Image directory " << endl;
string imagedir;
getline(cin, imagedir);
cout << endl;
Mat img = imread(imagedir);
if (img.empty())
{
cout << "Error!!!, Invalid image or wrong Directory, check your input and try again, see you later" << endl;
system("pause");
return -1;
}
auto imgh = img.cols;
auto imgw = img.rows;
cout << "The height and width of your image is " << " " << imgh << "x" << imgw << endl;
cout << endl;
cout << "Options And Type Of Operation" << endl;
Mat des;
auto Ksize1 = 3;
auto Ksize2 = 3;
do {
cout << "Enter E for the Entire Image or P for Part of the image" << endl;
char Option;
cin >> Option;
if (Option == 'P' || Option == 'p')
{
int x = 0;
int y = 0;
int imgheight;
int imgwidth;
cout << "Enter your ROI, The Location(point, x and y axis) You want to work on " << endl;
cout << endl;
cin >> x;
cin >> y;
cout << endl;
//if (x >= img.cols && x <= img.cols && y >= img.rows && y <=img.rows) Am having the first problem at this position..
{
if (x == 2 && y == 10) {
cout << "Enter the Height and Width of your ROI " << endl;
cout << endl;
cin >> imgheight;
cin >> imgwidth;
imgh = imgh - x;
imgw = imgw - y;
}
/* if (imgheight >= imgh && imgheight <= imgh && imgwidth >= imgw && imgwidth <= imgw)
{
cout << " Enter From 0 to 9 The Intercity Of The Blur You Want " << endl;
cout << endl;
int Ksize1, Ksize2;
cin >> Ksize1;
cin>> Ksize2;
if (Ksize1 >= 1 && Ksize1 <= 9 && Ksize2 >= 1 && Ksize2 <= 9)
{
Rect rect(x, y, imgh, imgw);
GaussianBlur(img, des, Size(Ksize1, Ksize2), 0);
string ImageO = "Original Image";
string ImageB = "GaussianBlured";
namedWindow(ImageO);
namedWindow(ImageB);
imshow(ImageO, img);
waitKey(0);
imshow(ImageB, des), waitKey(0);
}
}
}
}*/
//else if()
}
} while (false);
//cin.get();
system("pause");
return 0;
}
是的,我希望所有条件在继续之前都为真,即使所有条件都为真,下一个if语句也会被忽略,我想检查输入的位置是否在图像的高度和宽度之间。
答案 0 :(得分:1)
&&
意味着要执行代码,所有条件都必须为真。如果第一个条件为假,则将不执行代码。