37 #define sldr_btn_width 15
43 #define sldr_height 10
49 #define ctrl_pnl_height 200
62 #define scrn_height 480
69 #define p_height ( scrn_height + sldr_height + ctrl_pnl_height )
77 #define MOUSE_CALLBACK 0
133 #define STEPDOWN_BTN 4
146 #define BTN_INACTIVE 1
423 CvScalar
red = cvScalar( 0, 0, 255 );
424 CvScalar
green = cvScalar( 0, 255, 0 );
425 CvScalar
blue = cvScalar( 255, 0, 0 );
426 CvScalar
black = cvScalar( 0, 0, 0 );
427 CvScalar
white = cvScalar( 255, 255, 255 );
429 CvScalar
yellow = cvScalar( 0, 255, 255 );
430 CvScalar
gray = cvScalar( 242, 242, 242 );
431 CvScalar
orange = cvScalar( 0, 242, 255 );
432 CvScalar
voilet = cvScalar( 255, 0, 127 );
433 CvScalar
brown = cvScalar( 0, 0, 127 );
450 void resetField( IplImage* image,
int text_type );
462 void getButton( IplImage* image,
int btn_type,
int btn_state );
465 void getSpectrumVert( IplImage* image, CvScalar color1, CvScalar color2 );
468 void getSpectrumHorz( IplImage* image, CvScalar color1, CvScalar color2 );
474 void draw_square( IplImage* image, CvScalar color );
477 void draw_pause( IplImage* image, CvScalar color );
480 void draw_stepup( IplImage* image, CvScalar color );
486 void fill_color( IplImage* image, CvScalar color );
505 int main(
int argc,
char** argv ){
527 for(
int row=0; row<pnl->height; row++ ){
528 uchar* ptr = ( uchar* )(
pnl->imageData + row*
pnl->widthStep );
529 for(
int col=0; col<
pnl->width; col++ ){
530 ptr[ col*
pnl->nChannels + 0 ] = 226;
531 ptr[ col*
pnl->nChannels + 1 ] = 235;
532 ptr[ col*
pnl->nChannels + 2 ] = 240;
543 slider = cvCreateImageHeader( cvSize(
p_width, 10 ), IPL_DEPTH_8U, 3 );
547 for(
int row=0; row<slider->height; row++ ){
548 uchar* ptr = ( uchar* )(
slider->imageData + row*
slider->widthStep );
549 for(
int col=0; col<
slider->width; col++ ){
550 ptr[ col*
slider->nChannels + 0 ] = 94;
551 ptr[ col*
slider->nChannels + 1 ] = 118;
552 ptr[ col*
slider->nChannels + 2 ] = 254;
557 for(
int row=0; row<
sldr_btn->height; row++ ){
559 for(
int col=0; col<
sldr_btn->width; col++ ){
560 ptr[ col*
slider->nChannels + 0 ] = 100;
561 ptr[ col*
slider->nChannels + 1 ] = 150;
562 ptr[ col*
slider->nChannels + 2 ] = 100;
575 cvNamedWindow(
"Video Player", CV_WINDOW_AUTOSIZE );
592 vid = cvCaptureFromFile( argv[1] );
595 printf(
"Error loading the video file. Either missing file or codec not installed\n" );
602 fps = cvGetCaptureProperty(
vid, CV_CAP_PROP_FPS );
603 sldr_start = cvGetCaptureProperty(
vid, CV_CAP_PROP_POS_FRAMES );
604 fourcc_l = cvGetCaptureProperty(
vid, CV_CAP_PROP_FOURCC );
608 sldr_maxval = cvGetCaptureProperty(
vid, CV_CAP_PROP_FRAME_COUNT );
610 printf(
"Number of frames < 1. Cannot continue...\n" );
613 cvSetCaptureProperty(
615 CV_CAP_PROP_POS_FRAMES,
620 sprintf(
line,
"%d", (
int )cvRound(
fps ) );
634 printf(
"Cannot load video. Missing Codec : %s\n",
four_cc_str );
637 cvShowImage(
"Video Player",
player );
645 if( ( c = cvWaitKey( 1000/
fps ) )==27 ){
650 for(
int i = 0; i < (
step_val - 1 ); i++ ){
663 if( ( cur_frame = (
int )cvGetCaptureProperty(
vid, CV_CAP_PROP_POS_FRAMES ) )>=0 ){
684 cvShowImage(
"Video Player",
player );
691 cvDestroyWindow(
"Video Player" );
703 cvReleaseImageHeader( &
pnl );
705 cvReleaseImageHeader( &
slider );
710 cvReleaseImage( &
player );
713 cvReleaseCapture( &
vid );
738 frame_val = cvCeil( scale*pos );
752 int new_pos = cvCeil( scale*frame_val );
764 sprintf(
line,
"%d", frame_val );
785 IplImage* image = ( IplImage* )param;
790 case CV_EVENT_MOUSEMOVE: {
796 cvSetCaptureProperty(
vid, CV_CAP_PROP_POS_FRAMES, (
double )( cur_frame-1 ) );
807 case CV_EVENT_LBUTTONDOWN: {
814 cvSetCaptureProperty(
vid, CV_CAP_PROP_POS_FRAMES, (
double )( cur_frame-1 +
step_val -1 ) );
826 ( y > play_pause_btn_area.
y1 ) &&
827 ( y <= play_pause_btn_area.
y2 ) &&
828 ( x > play_pause_btn_area.
x1 ) &&
829 ( x <= play_pause_btn_area.
x2 )
847 ( y > stop_btn_area.
y1 ) &&
848 ( y <= stop_btn_area.
y2 ) &&
849 ( x > stop_btn_area.
x1 ) &&
850 ( x <= stop_btn_area.
x2 )
855 cvSetCaptureProperty(
vid, CV_CAP_PROP_POS_FRAMES, (
double )(
sldr_start-1 ) );
865 ( y > stepup_btn_area.
y1 ) &&
866 ( y <= stepup_btn_area.
y2 ) &&
867 ( x > stepup_btn_area.
x1 ) &&
868 ( x <= stepup_btn_area.
x2 )
870 int cur_frame = ( int )cvGetCaptureProperty(
vid, CV_CAP_PROP_POS_FRAMES );
873 for(
int i=0; i < (
step_val - 1 ); i++ ){
889 ( y > stepdown_btn_area.
y1 ) &&
890 ( y <= stepdown_btn_area.
y2 ) &&
891 ( x > stepdown_btn_area.
x1 ) &&
892 ( x <= stepdown_btn_area.
x2 )
895 int cur_frame = ( int )cvGetCaptureProperty(
vid, CV_CAP_PROP_POS_FRAMES );
899 cvSetCaptureProperty(
vid, CV_CAP_PROP_POS_FRAMES, (
double )( cur_frame - 1 - (
step_val - 1 ) ) );
913 ( y > step_edit_area.
y1 ) &&
914 ( y <= step_edit_area.
y2 ) &&
915 ( x > step_edit_area.
x1 ) &&
916 ( x <= step_edit_area.
x2 )
926 case CV_EVENT_LBUTTONUP: {
954 for(
int row=0; row<image->height; row++ ){
955 uchar *ptr = ( uchar* )( image->imageData + row*image->widthStep );
956 for(
int col=0; col<image->width; col++ ){
957 ptr[ col*image->nChannels + 0 ] = 226;
958 ptr[ col*image->nChannels + 1 ] = 235;
959 ptr[ col*image->nChannels + 2 ] = 240;
964 for(
int row=0; row<image->height; row++ ){
965 uchar *ptr = ( uchar* )( image->imageData + row*image->widthStep );
966 for(
int col=0; col<image->width; col++ ){
967 if( row==0 || row==image->height-1 || col==0 || col==image->width-1 ){
968 ptr[ col*image->nChannels + 0 ] = 0;
969 ptr[ col*image->nChannels + 1 ] = 0;
970 ptr[ col*image->nChannels + 2 ] = 0;
974 ptr[ col*image->nChannels + 0 ] = 255;
975 ptr[ col*image->nChannels + 1 ] = 255;
976 ptr[ col*image->nChannels + 2 ] = 255;
991 void getButton( IplImage* image,
int btn_type,
int btn_state ){
1030 for(
int row=0; row<image->height; row++ ){
1033 uchar *ptr = ( uchar* )( image->imageData + row*image->widthStep );
1034 for(
int col=0; col<image->width; col++ ){
1035 for(
int chl=0; chl<image->nChannels; chl++ ){
1036 ptr[ col*image->nChannels + chl] = color1.val[chl];
1041 if( row==image->height-1 ){
1042 uchar *ptr = ( uchar* )( image->imageData + row*image->widthStep );
1043 for(
int col=0; col<image->width; col++ ){
1044 for(
int chl=0; chl<image->nChannels; chl++ ){
1045 ptr[ col*image->nChannels + chl] = color2.val[chl];
1053 for(
int row=1; row<image->height-1; row++ ){
1054 uchar *ptr = ( uchar* )( image->imageData );
1055 for(
int col=0; col<image->width; col++ ){
1056 for(
int chl=0; chl<image->nChannels; chl++ ){
1057 ptr[ row*image->widthStep + col*image->nChannels + chl ] = (
1058 ptr[ ( image->height-1 )*image->widthStep + col*image->nChannels + chl ] - ptr[ col*image->nChannels + chl ] )*(
1059 row/( float )image->height ) + ptr[ col*image->nChannels + chl ];
1086 for(
int row=0; row<image->height; row++ ){
1087 uchar *ptr = ( uchar* )( image->imageData + row*image->widthStep );
1088 for(
int chl=0; chl<image->nChannels; chl++ ){
1089 ptr[chl] = color1.val[chl];
1090 ptr[ ( image->width-1 )*image->nChannels + chl ] = color2.val[ chl ];
1095 for(
int row=0; row<image->height; row++ ){
1096 uchar *ptr = ( uchar* )( image->imageData + row*image->widthStep );
1097 for(
int col=0; col<image->width; col++ ){
1098 for(
int chl=0; chl<image->nChannels; chl++ ){
1099 ptr[ col*image->nChannels + chl ] = ( ptr[ ( image->width - 1 )*image->nChannels + chl ] - ptr[ chl ] )*( col/( float )image->width ) + ptr[ chl ];
1124 cvPutText(
pnl,
"Step : ", cvPoint( 3, 60 ), &
font,
black );
1125 cvPutText(
pnl,
"File : ", cvPoint( 3, 140 ), &
font,
black );
1126 cvPutText(
pnl, filename, cvPoint( 65, 140 ), &
font,
black );
1128 cvPutText(
pnl,
"FPS : ", cvPoint( 700, 100 ), &
font,
black );
1129 cvPutText(
pnl,
"Current Frame : ", cvPoint( 3, 100 ), &
font,
black );
1130 cvPutText(
pnl,
"Total Frames : ", cvPoint( 300, 100 ), &
font,
black );
1131 cvPutText(
pnl,
"FOURCC : ", cvPoint( 668, 60 ), &
font,
black );
1132 cvPutText(
pnl,
"Status : ", cvPoint( 325, 30 ), &
font,
black );
1136 cur_frame_no = cvCreateImageHeader( cvSize( 120, 18), IPL_DEPTH_8U, 3 );
1144 numFrames = cvCreateImageHeader( cvSize( 120, 18), IPL_DEPTH_8U, 3 );
1152 step_edit = cvCreateImageHeader( cvSize( 50, 18), IPL_DEPTH_8U, 3 );
1157 step_edit_area.
x1 = col;
1166 fps_edit = cvCreateImageHeader( cvSize( 50, 18), IPL_DEPTH_8U, 3 );
1171 fps_edit_area.
x1 = col;
1178 four_cc_edit = cvCreateImageHeader( cvSize( 50, 22), IPL_DEPTH_8U, 3 );
1183 four_cc_edit_area.
x1 = col;
1190 play_pause_btn = cvCreateImageHeader( cvSize( 60, 18), IPL_DEPTH_8U, 3 );
1195 play_pause_btn_area.
x1 = col;
1202 stop_btn = cvCreateImageHeader( cvSize( 60, 18), IPL_DEPTH_8U, 3 );
1207 stop_btn_area.
x1 = col;
1214 stepup_btn = cvCreateImageHeader( cvSize( 60, 18), IPL_DEPTH_8U, 3 );
1219 stepup_btn_area.
x1 = col;
1226 stepdown_btn = cvCreateImageHeader( cvSize( 60, 18), IPL_DEPTH_8U, 3 );
1231 stepdown_btn_area.
x1 = col;
1238 status_edit = cvCreateImageHeader( cvSize( 130, 22), IPL_DEPTH_8U, 3 );
1243 status_edit_area.
x1 = col;
1262 CvPoint pt1, pt2, pt3;
1263 pt1.x = image->width/3;
1266 pt2.y = image->height - pt1.y;
1268 pt3.y = image->height/2;
1269 cvLine( image, pt1, pt2, color );
1270 cvLine( image, pt3, pt2, color );
1271 cvLine( image, pt1, pt3, color );
1287 pt1.x = 3*image->width/8;
1289 pt2.x = 5*image->width/8;
1290 pt2.y = image->height - pt1.y;
1291 cvRectangle( image, pt1, pt2, color );
1307 int y_end = image->height - y_start;
1309 CvPoint pt1, pt2, tmp1, tmp2;
1310 pt1.x = image->width/2;
1314 for(
int col=0; col<5; col++ ){
1315 tmp1.x = pt1.x + dist + col;
1317 tmp2.x = pt2.x + dist + col;
1319 cvLine( image, tmp1, tmp2, color );
1320 tmp1.x = pt1.x - dist - col;
1322 tmp2.x = pt2.x - dist - col;
1324 cvLine( image, tmp1, tmp2, color );
1332 bool start_fill =
false;
1333 for(
int row=0; row<image->height; row++ ){
1334 uchar *ptr = ( uchar* )( image->imageData + row*image->widthStep );
1335 for(
int col=0; col<image->width; col++ ){
1337 ( ptr[ col*image->nChannels + 0 ] == color.val[0] ) &&
1338 ( ptr[ col*image->nChannels + 1 ] == color.val[1] ) &&
1339 ( ptr[ col*image->nChannels + 2 ] == color.val[2] )
1350 ptr[ col*image->nChannels + 0 ] = color.val[0];
1351 ptr[ col*image->nChannels + 1 ] = color.val[1];
1352 ptr[ col*image->nChannels + 2 ] = color.val[2];
1360 CvPoint pt1, pt2, pt3, pt4;
1361 pt1.x = 2*image->width/8;
1362 pt2.x = 4*image->width/8;
1366 int y_end = image->height/2 ;
1367 for(
int row=y_start; row<=y_end; row++ ){
1368 pt1.x = pt1.x + row - y_start;
1369 pt2.x = pt2.x + row - y_start;
1374 pt3.y = image->height - row;
1376 cvLine( image, pt1, pt2, color );
1377 cvLine( image, pt3, pt4, color );
1383 CvPoint pt1, pt2, pt3, pt4;
1384 pt1.x = 4*image->width/8;
1385 pt2.x = 6*image->width/8;
1389 int y_end = image->height/2 ;
1390 for(
int row=y_start; row<=y_end; row++ ){
1391 pt1.x = pt1.x - row + y_start;
1392 pt2.x = pt2.x - row + y_start;
1397 pt3.y = image->height - row;
1399 cvLine( image, pt1, pt2, color );
1400 cvLine( image, pt3, pt4, color );
1413 char temp_text[ 20 ];
1415 sprintf( temp_text,
"" );
1439 if( c>=48 && c<=57 ){
1440 sprintf( temp_text,
"%s%c",
edit_text, c );
1441 if( ( frame_val + atoi( temp_text ) )>=0 && ( frame_val + atoi( temp_text ) )<=
sldr_maxval && ( atoi( temp_text )!=0 ) ){
1448 for(
int count=0; count<( strlen(
edit_text )-1 ); count++ ){
1449 sprintf( temp_text,
"%s%c", temp_text,
edit_text[ count ] );
#define sldr_btn_width
Default value for the Slider Button's width.
int thickness
Font's Thickness parameter.
Field_Area stepup_btn_area
Step Up Button coordinates.
void fill_color(IplImage *image, CvScalar color)
Function to fill a symbol with a given color.
#define p_height
Height of the video player.
#define STEPDOWN_BTN
Alias for step-down button.
#define PAUSE_BTN
Alias for pause button.
void type_step(char c, int frame_val)
Function to edit a textbox.
IplImage * step_edit
Pointer to the Step textbox.
CvScalar black
Black color.
void resetField(IplImage *image, int text_type)
Function to reset a given text field.
IplImage * slider
Pointer to the slider-strip sub-image.
CvScalar brown
Brown color.
#define STATIC_TEXT
Alias for static-text field.
int line_type
Font's Line-type parameter.
IplImage * cur_frame_no
Pointer to current frame number static-text.
CvScalar green
Green color.
IplImage * numFrames
Pointer to Total Frames static-text.
IplImage * fps_edit
Pointer to FPS (Frames Per Second) static-text.
CvFont font_bold
Bold font.
IplImage * stepdown_btn
Pointer to step_down button area.
bool processing
True when some processing is carried out.
char four_cc_str[4]
Memory to hold the Four Character Code (FOUR_CC).
IplImage * four_cc_edit
Pointer to FOUR_CC static-text.
void initialize_pnl(char *filename)
Function to initialise the control pannel.
int sldr_maxval
The maximum number of frames in the video.
IplImage * frame_area
Pointer to the frame-area sub-image.
#define ctrl_pnl_height
Default value for Control Pannel's height.
#define PLAY_BTN
Alias for play button.
bool playing
True when the video is being played.
#define STOP_BTN
Alias for stop button.
int moveSlider(int pos, int call_from)
Custome slider's callback function.
CvScalar yellow
Yellow color.
void draw_square(IplImage *image, CvScalar color)
Function to draw a square on a given image.
CvScalar voilet
Voilet color.
CvCapture * vid
Pointer to CvCapture structure.
IplImage * stop_btn
Pointer to stop button area.
int x2
x coordinate of the bottom-right corrner.
char blink_char
Threshold to toogle the blink_char.
char * fourcc
Four_CC temporary string.
int main(int argc, char **argv)
void draw_pause(IplImage *image, CvScalar color)
Function to draw a pause symbol on a given image.
#define p_width
Width of the video player.
double fps
Frames per second.
CvFont font_bold_italic
Bold Italic font.
CvFont font_italic
Italic font.
double vscale
Font's Vertical Scale parameter.
IplImage * oslider
Pointer to temporary slider-value static-text sub-image.
void getSpectrumVert(IplImage *image, CvScalar color1, CvScalar color2)
Function to vertically color a button.
Field_Area stop_btn_area
Stop Button coordinates.
#define STEPUP_BTN
Alias for step-up button.
#define OTHER_CALLS
Alias for function call made by any function other than MOUSE's callback or Textbox Editor's function...
IplImage * status_edit
Pointer to "Status" static-text.
long fourcc_l
Four Character Code.
bool sldr_moving
Ture when slider is moving.
Field_Area fps_edit_area
FPS static-text coordinates.
int y2
y coordinate of the bottom-right corrner.
IplImage * sldr_val
Pointer to the slider-value static-text sub-image.
void getSpectrumHorz(IplImage *image, CvScalar color1, CvScalar color2)
Function to horizontaly color a button.
IplImage * sldr_btn
Pointer to the slider-button sub-image.
IplImage * player
Pointer to the main image.
int blink_count
Blinker count.
char line[20]
Memory to hold any string temporarily.
bool blinking
True when blinking character is set.
int y1
y coordinate of the top-left corrner.
#define MOUSE_CALLBACK
Alias for function call made by the MOUSE's callback.
#define EDIT_TEXT
Alias for text-box field.
Field_Area four_cc_edit_area
FOUR_CC static-text coordinates.
CvScalar light_yellow
Light Yellow color.
void draw_stepdown(IplImage *image, CvScalar color)
Function to draw a step-down symbol on a given image.
void my_mouse_callback(int event, int x, int y, int flags, void *param)
Mouse's callback function.
Field_Area play_pause_btn_area
The blinking character, toogled with an underscore (_).
void getButton(IplImage *image, int btn_type, int btn_state)
Function to get a new button.
int font_face_italic
Font face.
IplImage * play_pause_btn
Pointer to play/pause button area.
double hscale
Font's Horizontal Scale parameter.
char edit_text[20]
Memory to hold a textbox string temporarily.
Field_Area stepdown_btn_area
Step Down Button coordinates.
char status_line[15]
Memory to hold the "status" string.
#define sldr_height
Default value for the Slider Button's height.
void change_status()
Function to change the status message.
IplImage * old_frame
Pointer to the previously fetched frame.
bool typing_step
True when any textbox value is being edited.
void resetAllEdits()
Function to reset all fields to their previous contents.
int sldr_start
Indicates the starting position (frame number) of the slider.
#define BTN_ACTIVE
Alias for an active button.
CvScalar white
White color.
Structure to store the top-left and botton-right corner coordinates of various fields & buttons...
IplImage * frame
Pointer to the fetched frame sub-image.
void draw_triangle(IplImage *image, CvScalar color)
Function to draw a triangle on a given image.
Field_Area step_edit_area
Step textbox coordinates.
#define scrn_height
Height of the video-display area.
double shear
Font's Shear parameter.
CvScalar orange
Orange color.
IplImage * pnl
Pointer to the control-pannel sub-image.
IplImage * stepup_btn
Pointer to step_up button area.
Field_Area status_edit_area
Status string coordinates.
int x1
x coordinate of the top-left corrner.
void draw_stepup(IplImage *image, CvScalar color)
Function to draw a step-up symbol on a given image.