OpenCV image filters

EDIT: So embarrissing! Just found out I missed a lot of "}" in the code... I will get back, when I have something intelligent to ask...


This is my first post here, so please let me know, if there are any problems in the way, I´m posting...

I´m trying to program 9 different image filters that alters an image by pressing 9 different letters on the keyboard. (Right now its the same filter for all 9 letters, but I will get back to that later...)

I get this error when compiling:

1>c:\users\thomas\documents\visual studio 2008\projects\filtersforimageprocessing\filtersforimageprocessing\main.cpp(37) : error C2360: initialization of 'q' is skipped by 'case' label

What am I doing wrong?

Thx in advance

- Victor

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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

#include <iostream>
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"

using namespace std;

int main(){

	IplImage *img = cvLoadImage ("breakfast.jpg", 1);
	cvNamedWindow ("breakfast", CV_WINDOW_AUTOSIZE);


int nc = img-> nChannels;
int ws = img-> widthStep;
int h = img-> height;
int w = img-> width;

	char keyPress = 0;

while(keyPress != 27){
	cvShowImage ("breakfast", img);
	keyPress = cvWaitKey();
switch(keyPress){

case 'a':
	
	for( int y = 0; y < h; y++)
			for( int x = 0; x < w; x++)
				for( int q = 0; q < nc; q++) {

			img->imageData[y*ws+x*nc+q] = (unsigned char)img->imageData[y*ws+x*nc+q] * 1.1f;
				}
			break;
								

case 'b':

	for( int y = 0; y < h; y++)
			for( int x = 0; x < w; x++)
				for( int q = 0; q < nc; q++) {

			img->imageData[y*ws+x*nc+q] = (unsigned char)img->imageData[y*ws+x*nc+q] / 1.1f;

				}
		break;

case 'c':

		for( int y = 0; y < h; y++)
			for( int x = 0; x < w; x++)
				for( int q = 0; q < nc; q++) {

			img->imageData[y*ws+x*nc+q] = (unsigned char)img->imageData[y*ws+x*nc+q] * 1.1f;
				}
		break;

case 'd':

		for( int y = 0; y < h; y++)
			for( int x = 0; x < w; x++)
				for( int q = 0; q < nc; q++) {

			img->imageData[y*ws+x*nc+q] = (unsigned char)img->imageData[y*ws+x*nc+q] * 1.1f;
				}
		break;

case 'e':

		for( int y = 0; y < h; y++)
			for( int x = 0; x < w; x++)
				for( int q = 0; q < nc; q++) {

			img->imageData[y*ws+x*nc+q] = (unsigned char)img->imageData[y*ws+x*nc+q] * 1.1f;
				}
		break;

case 'f':

		for( int y = 0; y < h; y++)
			for( int x = 0; x < w; x++)
				for( int q = 0; q < nc; q++) {

			img->imageData[y*ws+x*nc+q] = (unsigned char)img->imageData[y*ws+x*nc+q] * 1.1f;
				}
		break;

case 'g':

		for( int y = 0; y < h; y++)
			for( int x = 0; x < w; x++)
				for( int q = 0; q < nc; q++) {

			img->imageData[y*ws+x*nc+q] = (unsigned char)img->imageData[y*ws+x*nc+q] * 1.1f;
				}
		break;

case 'h':

		for( int y = 0; y < h; y++)
			for( int x = 0; x < w; x++)
				for( int q = 0; q < nc; q++) {

			img->imageData[y*ws+x*nc+q] = (unsigned char)img->imageData[y*ws+x*nc+q] / 1.1f;
				}
		break;

case 'i':

		for( int y = 0; y < h; y++)
			for( int x = 0; x < w; x++)
				for( int q = 0; q < nc; q++) {

			img->imageData[y*ws+x*nc+q] = (unsigned char)img->imageData[y*ws+x*nc+q] * 1.1f;
				}
		break;

	}
}



cvWaitKey(0);

return 0;

}

Last edited on
Ok, 2 new questions:

Why do I get the following warning on line 33 and all lines similar to line 33:


1>c:\users\thomas\documents\visual studio 2008\projects\filtersforimageprocessing\filtersforimageprocessing\main.cpp(32) : warning C4244: '=' : conversion from 'float' to 'char', possible loss of data

Is this the correct forum to ask OpenCV related questions?
Hello victorpax,

1>c:\users\thomas\documents\visual studio 2008\projects\filtersforimageprocessing\filtersforimageprocessing\main.cpp(37) : error C2360: initialization of 'q' is skipped by 'case' label

you can avoid this by
1
2
3
4
5
6
7
8
9
10
case 'a':
    {    // <--- note the '{'
       for( int y = 0; y < h; y++)
            for( int x = 0; x < w; x++)
                for( int q = 0; q < nc; q++) {

            img->imageData[y*ws+x*nc+q] = (unsigned char)img->imageData[y*ws+x*nc+q] * 1.1f;
                }
     } // <--- note the '}'
     break;


1>c:\users\thomas\documents\visual studio 2008\projects\filtersforimageprocessing\filtersforimageprocessing\main.cpp(32) : warning C4244: '=' : conversion from 'float' to 'char', possible loss of data


an expression like this (unsigned char)img->imageData[y*ws+x*nc+q] * 1.1f; results in a floating number and img->imageData[y*ws+x*nc+q] is obviously a char.
So if you want to avoid that warning write:
img->imageData[y*ws+x*nc+q] = (unsigned char)(img->imageData[y*ws+x*nc+q] * 1.1f); note the '()'
if you're sure that it is what you want because that's indeed a 'possible loss of data'


Is this the correct forum to ask OpenCV related questions?

well, it's not overly OpenCV related
Topic archived. No new replies allowed.