statement codes inside my if statement not executing

Jan 13, 2019 at 6:45pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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 >= 0 && x <= img.cols && y >= 0 && y <= img.rows)
			{
				cout << "Enter the Height and Width of your ROI " << endl;
				cout << endl;
				cin >> imgheight;
				cin >> imgwidth;
				imgh = imgh - x;
				imgw = imgw - y;
				cout << "new-width is :" << imgw << endl;
				if (imgheight >= 0 && imgheight <= imgh && imgwidth >=0 && 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 <= 35 && Ksize2 >= 1 && Ksize2 <= 35)
					{
						Rect rect(x, y, imgheight, imgwidth);
						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 (Option == 'E' || Option == 'e')
		{
			auto x = 0;
			auto y = 0;
			int imgheight = img.cols;
			int imgwidth = img.rows;
			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 <= 35 && Ksize2 >= 1 && Ksize2 <= 35)
			{
				Rect rect(x, y, imgheight, imgwidth);
				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);

			}

		  
		}
	
	} while (true, cout<<"Try Again"<<endl);
Last edited on Jan 14, 2019 at 7:06pm
Jan 13, 2019 at 7:39pm
This condition
x >= img.cols && x <= img.cols && y >= img.rows && y <=img.rows
is in fact
x == img.cols && y == img.rows

Did you mean right that?
Jan 13, 2019 at 8:03pm
x is the horizontal figure while y is the vertical one, actually my problem is that the codes inside the the if statement are not running
Jan 14, 2019 at 11:05am
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) jugu has pointed out an important issue with the logic of your code, that may well be the cause of your problem. You would do well to take it seriously, understand it, and answer it, rather than brushing it off with a glib answer that doesn't actually address the point they're making.
Jan 14, 2019 at 3:53pm
either use a debugger or a print statement on each condition of the if statement that did not fire when expected ... you need the value of each variable and optionally the conditional result.
eg
cout << option << endl;
cout << x << endl;
cout << y << endl;
and img.cols and img.rows if that is not enough to see the issue.

what you will probably find is that your if statement is illogical.
x >= img.cols && x <= img.cols
if x is bigger than it AND x is less than it only happens when its exactly equal.
this logic looks incorrect, which is right back to what jugu told you, but with more words.
Jan 14, 2019 at 6:01pm
Please paste the end of your do-while loop. I can see "do" but no "while" at the end. Maybe there's a bug in the loop condition...
Jan 14, 2019 at 6:59pm
i will be posting the updated code now, thanks alot guys
Jan 14, 2019 at 7:14pm
ok, can you explain what problem you are having NOW that you updated the code?
Jan 14, 2019 at 7:19pm
ok i wanted to check if the inputted position is not smaller or greater than the length and width of the image, have actually gotten it to work though, much thanks
Jan 15, 2019 at 11:54am
Please DON'T go back and replace your old posts with new code. It makes the thread incomprehensible for those who are trying to read it and learn from it. If you have updated code you want to post in a thread, put it into a new reply.
Topic archived. No new replies allowed.