# Include "cvcam. H"
# Include "cv. H"
# Include "highgui. H"
# Include <cstdio>
/* Void example2_4 (iplimage * image)
{
Cvnamedwindow ("Example4-in ");
Cvnamedwindow ("Example4-out ");
Cvshowimage ("The Example4-in", image );
Iplimage * out = cvcreateimage (cvgetsize (image ),
Ipl_depth_8u, // Number of BITs
3); // how many colors
Cvsmooth (image, out, cv_gaussian, 3 );
Cvshowimage ("Example4-out", out );
Cvreleaseimage (& out );
Cvwaitkey (0 );
Cvdestroywindow ("Example4-in ");
Cvdestroywindow ("Example4-out ");
}*/
Int g_slider_position = 0;
Cvcapture * g_capture = NULL;
Void ontrackbarslide (int pos)
{
// Pos = g_slider_position;
Cvsetcaptureproperty (g_capture, cv_cap_prop_pos_frames, POS );
}
/* Void callback (iplimage * image) // draw a horizontal blue line on the Image
{
Iplimage * image1 = image;
Int I, J;
Assert (image );
For (I = 0; I <image1-> height/2; I + = 10)
{
For (j = (image1-> widthstep) * I;
J <(image1-> widthstep) * (I + 1 );
J + = image1-> nchannels)
{
Image1-> imagedata [J] = (char) 255;
Image1-> imagedata [J + 1] = 0;
Image1-> imagedata [J + 2] = 0;
}
}
}*/
Void main (INT argc, char ** argv)
{
// Iplimage * IMG = cvloadimage ("C: // zhongqiu.bmp", 1 );//
Cvnamedwindow ("example1", cv_window_autosize );
// G_capture = cvcreatefilecapture ("F: // opencv // aviconsoleopencv // avid. Avi ");
// G_capture = cvcapturefromcam (0); // capture from Video device #0
G_capture = cvcreatecameracapture (0 );
Int frames = (INT) cvgetcaptureproperty (g_capture, cv_cap_prop_frame_count );
If (frames! = 0 ){
Cvcreatetrackbar ("position ",
"Example1 ",
& G_slider_position,
Frames,
Ontrackbarslide );
}
Iplimage * frame;
Int height, width, step, channels;
Uchar * data;
// Uchar * data2;
Int I, J, K, X, Y, T;
// Get the image data
While (1 ){
Frame = cvqueryframe (g_capture );
If (! Frame) break;
// Cvsettrackbarpos ("position", "example1", g_slider_position ++ );
Assert (FRAME );
Height = frame-> height;
Width = frame-> width;
Step = frame-> widthstep;
Channels = frame-> nchannels;
Data = (uchar *) frame-> imagedata;
/* For (I = 0; I <frame-> height; I + = 10)
{
For (j = (frame-> widthstep) * I;
J <(frame-> widthstep) * (I + 1 );
J + = frame-> nchannels)
{
Frame-> imagedata [J] = (char) 255;
Frame-> imagedata [J + 1] = 0;
Frame-> imagedata [J + 2] = 0;
}
}
*/
// The following are the core operators:
For (I = 0; I For (j = 0; j <width; j ++ ){
For (k = 0; k <channels; k ++ ){
// Data [I * Step + J * channels + k] = 255-data [I * Step + J * channels + k];
X = data [I * Step + J * channels + k]-data [(I + 1) * Step + J * channels + k];
Y = data [I * Step + J * channels + k]-data [I * Step + (J + 1) * channels + k];
T = (INT) (SQRT (x * x + y * Y) + 0.5 );
If (T> 255)
T = 255;
Data [I * Step + J * channels + k] = T;
}
}
}
// Cvcamsetproperty (0, cvcam_prop_callback, callback );
// Example2_4 (FRAME );
Cvshowimage ("example1", frame );
Char c = cvwaitkey (33 );
If (C = 27) break;
}
// Cvnamedwindow ("example1", 0 );
// Cvshowimage ("example1", IMG );
Cvreleasecapture (& g_capture );
Cvdestroywindow ("example1 ");
}