Ask Your Question

Revision history [back]

how can I make this code work with Mat?

#include <opencv/cv.h>

In my code where I state if (c == 's')

how do I save Mat imgH = frame + Scalar(0.299bright, 0.587bright, 0.114*bright); to a index-able image to my hard drive? I tried imwrite and it just crashes any ideas what I'm missing?

#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <cstdlib>
#include <windows.h> 

using namespace cv;
using namespace std;

double Brightness;
double Contrast ;
double Saturation;
double Gain;
double Exposure; 


int main(int argc, char* argv[])
{

    VideoCapture cap(0); // open the video camera no. 0


    if (!cap.isOpened()){
         cout << "Cannot open the video cam" << endl;
         return -1;
    }



    double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
    double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
    cap.set(CV_CAP_PROP_AUTO_EXPOSURE,0.0 );                // turn off auto exposure 

    // Get fixed Cam Properties

    Brightness = cap.get(CV_CAP_PROP_BRIGHTNESS); 
    Contrast   = cap.get(CV_CAP_PROP_CONTRAST );
    Saturation = cap.get(CV_CAP_PROP_SATURATION);
    Gain       = cap.get(CV_CAP_PROP_GAIN);
    Exposure   = cap.get(CV_CAP_PROP_AUTO_EXPOSURE ); 


    // Display Them 

    cout<<"===================================="<<endl;
    cout<<"Default Brightness -------> "<<Brightness<<endl;
    cout<<"Default Contrast----------> "<<Contrast<<endl;
    cout<<"Default Saturation--------> "<<Saturation<<endl;
    cout<<"Default Gain--------------> "<<Gain<<endl;
    cout<<"Default exp --------------> "<<Exposure<<endl; 
    cout<<"===================================="<<endl;


    // console adjustment for testing  

    cout << "\nFrame size : " << dWidth << " x " << dHeight << endl;
    int bright; 
    cout<< "\nbrightness level -100 - 100 " << endl; 
    cin>> bright;  
    cout <<"\nbrightness level: " <<bright <<endl; 

    namedWindow("Video"); //create a window called "MyVideo"


    while(1) 
    {

        Mat frame;

        bool bFrame = cap.read(frame); // read a new frame from video
        int x = 200;
        Sleep(x); 

        if (!bFrame){
             cout << "Cannot read a frame from video stream" << endl;
             break;
        }


         Mat imgH = frame + Scalar(0.299*bright, 0.587*bright, 0.114*bright); // convert RGB to Luminance percieved 



         imshow("Video", imgH ); //show the frame in "Video" window with adjusted luminance value


        char c =waitKey(30); 


        // Camera Properties 

        if (c == 'p'){ 
            cap.set(CV_CAP_PROP_SETTINGS , 1 ); 
        }

        if(c== 's'){

//how do I save Mat imgH = frame + Scalar(0.299bright, 0.587bright, 0.114*bright); //to a index-able image to my hard drive? I tried imwrite and it just crashes }

//Exit

        if (c == 27){ 

            cout << "esc key is pressed by user" << endl;

            return 0;  
       }
     }

    return 0;
}

how can I make this code imwrite work with Mat?a Mat video frame?

#include <opencv/cv.h>

In my code where I state if (c == 's')

how do I save Mat imgH = frame + Scalar(0.299bright, 0.587bright, 0.114*bright); to a index-able image to my hard drive? I tried imwrite and it just crashes any ideas what I'm missing?

#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <cstdlib>
#include <windows.h> 

using namespace cv;
using namespace std;

double Brightness;
double Contrast ;
double Saturation;
double Gain;
double Exposure; 


int main(int argc, char* argv[])
{

    VideoCapture cap(0); // open the video camera no. 0


    if (!cap.isOpened()){
         cout << "Cannot open the video cam" << endl;
         return -1;
    }



    double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
    double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
    cap.set(CV_CAP_PROP_AUTO_EXPOSURE,0.0 );                // turn off auto exposure 

    // Get fixed Cam Properties

    Brightness = cap.get(CV_CAP_PROP_BRIGHTNESS); 
    Contrast   = cap.get(CV_CAP_PROP_CONTRAST );
    Saturation = cap.get(CV_CAP_PROP_SATURATION);
    Gain       = cap.get(CV_CAP_PROP_GAIN);
    Exposure   = cap.get(CV_CAP_PROP_AUTO_EXPOSURE ); 


    // Display Them 

    cout<<"===================================="<<endl;
    cout<<"Default Brightness -------> "<<Brightness<<endl;
    cout<<"Default Contrast----------> "<<Contrast<<endl;
    cout<<"Default Saturation--------> "<<Saturation<<endl;
    cout<<"Default Gain--------------> "<<Gain<<endl;
    cout<<"Default exp --------------> "<<Exposure<<endl; 
    cout<<"===================================="<<endl;


    // console adjustment for testing  

    cout << "\nFrame size : " << dWidth << " x " << dHeight << endl;
    int bright; 
    cout<< "\nbrightness level -100 - 100 " << endl; 
    cin>> bright;  
    cout <<"\nbrightness level: " <<bright <<endl; 

    namedWindow("Video"); //create a window called "MyVideo"


    while(1) 
    {

        Mat frame;

        bool bFrame = cap.read(frame); // read a new frame from video
        int x = 200;
        Sleep(x); 

        if (!bFrame){
             cout << "Cannot read a frame from video stream" << endl;
             break;
        }


         Mat imgH = frame + Scalar(0.299*bright, Scalar(0.114*bright, 0.587*bright, 0.114*bright); 0.299*bright); // convert RGB BGR to Luminance percieved 



         imshow("Video", imgH ); //show the frame in "Video" window with adjusted luminance luminescence value


        char c =waitKey(30); 


        // Camera Properties 

        if (c == 'p'){ 
            cap.set(CV_CAP_PROP_SETTINGS , 1 ); 
        }

        if(c== 's'){

//how do I save Mat imgH = frame + Scalar(0.299bright, 0.587bright, 0.114*bright); //to a index-able image to my hard drive? I tried a string with imwrite and it just crashes

 char filename[80];
 sprintf(filename,"C://pics//test_%d.png",i); // extension doesn't help tried jpg bmp and png 
 imwrite(filename, frame);
 i++;

}

//Exit

        if (c == 27){ 

            cout << "esc key is pressed by user" << endl;

            return 0;  
       }
     }

    return 0;
}

how can I make imwrite work with a Mat video frame?

#include <opencv/cv.h>

In my code where I state if (c == 's')

how do I save Mat imgH = frame + Scalar(0.299bright, 0.587bright, 0.114*bright); to a index-able image to my hard drive? I tried imwrite and it just crashes any ideas what I'm missing?

#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <cstdlib>
#include <windows.h> 

using namespace cv;
using namespace std;

double Brightness;
double Contrast ;
double Saturation;
double Gain;
double Exposure; 

char buffer[100]; 
int i = 0; 
int c = 1; 

int main(int argc, char* argv[])
{

    VideoCapture cap(0); // open the video camera no. 0


    if (!cap.isOpened()){
         cout << "Cannot open the video cam" << endl;
         return -1;
    }
 
    double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
    double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
    cap.set(CV_CAP_PROP_AUTO_EXPOSURE,0.0 );                // turn off auto exposure 

    // Get fixed Cam Properties

    Brightness = cap.get(CV_CAP_PROP_BRIGHTNESS); 
    Contrast   = cap.get(CV_CAP_PROP_CONTRAST );
    Saturation = cap.get(CV_CAP_PROP_SATURATION);
    Gain       = cap.get(CV_CAP_PROP_GAIN);
    Exposure   = cap.get(CV_CAP_PROP_AUTO_EXPOSURE ); 


    // Display Them 

    cout<<"===================================="<<endl;
    cout<<"Default Brightness -------> "<<Brightness<<endl;
    cout<<"Default Contrast----------> "<<Contrast<<endl;
    cout<<"Default Saturation--------> "<<Saturation<<endl;
    cout<<"Default Gain--------------> "<<Gain<<endl;
    cout<<"Default exp --------------> "<<Exposure<<endl; 
    cout<<"===================================="<<endl;


    // console adjustment for testing  

    cout << "\nFrame size : " << dWidth << " x " << dHeight << endl;
    int bright; 
    cout<< "\nbrightness level -100 - 100 " << endl; 
    cin>> bright;  
    cout <<"\nbrightness level: " <<bright <<endl; 

    namedWindow("Video"); //create a window called "MyVideo"


    while(1) for(;;) 
    {
         Mat frame;
        cap >> frame; 

            int x = 200;
            Sleep(x);           
        bool bFrame = cap.read(frame); // read a new frame from video
        int x = 200;
        Sleep(x); 

        if (!bFrame){
             cout << "Cannot read a frame from video stream" << endl;
             break;
        }


         Mat imgH = frame + Scalar(0.114*bright, 0.587*bright, 0.299*bright); // convert BGR to Luminance percieved 



         // imshow("Video", imgH ); //show the frame in "Video" window with adjusted luminescence value


        char c ch =waitKey(30); 
        sprintf(buffer, "c:\\pics\\imge%d.jpg" , c); 



        // Camera Properties 

        if (c (ch == 'p'){ 
            cap.set(CV_CAP_PROP_SETTINGS , 1 ); 
        }

        if(c== if(ch== 's'){

//how do I save Mat imgH = frame + Scalar(0.299bright, 0.587bright, 0.114*bright); //to a index-able image to my hard drive? I tried a string with imwrite and it just crashes

  char filename[80];
 sprintf(filename,"C://pics//test_%d.png",i); // extension doesn't help tried jpg bmp and png 
 imwrite(filename, frame);
 i++;
 cvWaitKey(10); 
  cout<< "new frame in window " <<buffer<<endl;  
  imshow("Video", imgH ); 
  imwrite(buffer, imgH); // this is not working!  
  c++;

}


//Exit

        if (c (ch == 27){ 

            cout << "esc key is pressed by user" << endl;

            return 0;  
       }
     }

    return 0;
}

how can I make imwrite work with a Mat video frame?

#include <opencv/cv.h>

In my code where I state if (c == 's')

how do I save Mat imgH = frame + Scalar(0.299bright, 0.587bright, 0.114*bright); to a index-able image to my hard drive? I tried imwrite and it just crashes any ideas what I'm missing?

#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <cstdlib>
#include <windows.h> 

using namespace cv;
using namespace std;

double Brightness;
double Contrast ;
double Saturation;
double Gain;
double Exposure; 

char buffer[100]; 
int i = 0; 
int c = 1; 

int main(int argc, char* argv[])
{

    VideoCapture cap(0); // open the video camera no. 0


    if (!cap.isOpened()){
         cout << "Cannot open the video cam" << endl;
         return -1;
    }

    double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
    double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
    cap.set(CV_CAP_PROP_AUTO_EXPOSURE,0.0 );                // turn off auto exposure 

    // Get fixed Cam Properties

    Brightness = cap.get(CV_CAP_PROP_BRIGHTNESS); 
    Contrast   = cap.get(CV_CAP_PROP_CONTRAST );
    Saturation = cap.get(CV_CAP_PROP_SATURATION);
    Gain       = cap.get(CV_CAP_PROP_GAIN);
    Exposure   = cap.get(CV_CAP_PROP_AUTO_EXPOSURE ); 


    // Display Them 

    cout<<"===================================="<<endl;
    cout<<"Default Brightness -------> "<<Brightness<<endl;
    cout<<"Default Contrast----------> "<<Contrast<<endl;
    cout<<"Default Saturation--------> "<<Saturation<<endl;
    cout<<"Default Gain--------------> "<<Gain<<endl;
    cout<<"Default exp --------------> "<<Exposure<<endl; 
    cout<<"===================================="<<endl;


    // console adjustment for testing  

    cout << "\nFrame size : " << dWidth << " x " << dHeight << endl;
    int bright; 
    cout<< "\nbrightness level -100 - 100 " << endl; 
    cin>> bright;  
    cout <<"\nbrightness level: " <<bright <<endl; 

    namedWindow("Video"); //create a window called "MyVideo"


    for(;;) 
    {
        Mat frame;
        cap >> frame; 

         int x = 200;
         Sleep(x);           
        bool bFrame = cap.read(frame); // read a new frame from video
        int x = 200;
        Sleep(x); 



         Mat imgH = frame + Scalar(0.114*bright, 0.587*bright, 0.299*bright); // convert BGR to Luminance percieved 



        // imshow("Video", imgH ); //show the frame in "Video" window with adjusted luminescence value


        char ch =waitKey(30); 
        sprintf(buffer, "c:\\pics\\imge%d.jpg" , c); 



        // Camera Properties 

        if (ch == 'p'){ 
            cap.set(CV_CAP_PROP_SETTINGS , 1 ); 
        }

 if(ch== 's'){

's'){ //how do I save Mat imgH = frame + Scalar(0.299bright, 0.587bright, Scalar(0.299*bright, 0.587*bright, 0.114*bright); //to a index-able image to my hard drive? I tried a this string with imwrite and it just crashes

crashes. 
    char filename[80];
   cvWaitKey(10); 
   cout<< "new frame in window " <<buffer<<endl;  
   imshow("Video", imgH ); 
   imwrite(buffer, imgH); // this is not working!  
   c++;

}
//Exit

     if (ch == 27){ 

           cout << "esc key is pressed by user" << endl;
           return 0;  
       }
     }

    return 0;
}

how can I make imwrite work with a Mat video frame?

#include <opencv/cv.h>

In my code where I state if (c == 's')

how do I save Mat imgH = frame + Scalar(0.299bright, 0.587bright, 0.114*bright); to a index-able image to my hard drive? I tried imwrite and it just crashes any ideas what I'm missing?

#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <cstdlib>
#include <windows.h> 

using namespace cv;
using namespace std;

double Brightness;
double Contrast ;
double Saturation;
double Gain;
double Exposure; 

char buffer[100]; 
int i = 0; 
int c = 1; 

int main(int argc, char* argv[])
{

    VideoCapture cap(0); // open the video camera no. 0


    if (!cap.isOpened()){
         cout << "Cannot open the video cam" << endl;
         return -1;
    }

    double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
    double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
    cap.set(CV_CAP_PROP_AUTO_EXPOSURE,0.0 );                // turn off auto exposure 

    // Get fixed Cam Properties

    Brightness = cap.get(CV_CAP_PROP_BRIGHTNESS); 
    Contrast   = cap.get(CV_CAP_PROP_CONTRAST );
    Saturation = cap.get(CV_CAP_PROP_SATURATION);
    Gain       = cap.get(CV_CAP_PROP_GAIN);
    Exposure   = cap.get(CV_CAP_PROP_AUTO_EXPOSURE ); 


    // Display Them 

    cout<<"===================================="<<endl;
    cout<<"Default Brightness -------> "<<Brightness<<endl;
    cout<<"Default Contrast----------> "<<Contrast<<endl;
    cout<<"Default Saturation--------> "<<Saturation<<endl;
    cout<<"Default Gain--------------> "<<Gain<<endl;
    cout<<"Default exp --------------> "<<Exposure<<endl; 
    cout<<"===================================="<<endl;


    // console adjustment for testing  

    cout << "\nFrame size : " << dWidth << " x " << dHeight << endl;
    int bright; 
    cout<< "\nbrightness level -100 - 100 " << endl; 
    cin>> bright;  
    cout <<"\nbrightness level: " <<bright <<endl; 

    namedWindow("Video"); //create a window called "MyVideo"


    for(;;) 
    {
        Mat frame;
        cap >> frame; 

        int x = 200;
        Sleep(x);           
        bool bFrame = cap.read(frame); // read a new frame from video
        int x = 200;
        Sleep(x); 

         Mat imgH = frame + Scalar(0.114*bright, 0.587*bright, 0.299*bright); // convert BGR to Luminance percieved  

        // imshow("Video", imgH ); //show the frame in "Video" window with adjusted luminescence value

         char ch =waitKey(30); 
        sprintf(buffer, "c:\\pics\\imge%d.jpg" , c);  


        // Camera Properties 

        if (ch == 'p'){ 
            cap.set(CV_CAP_PROP_SETTINGS , 1 ); 
        }

       if(ch== 's'){ 
    //how do I save  Mat imgH = frame + Scalar(0.299*bright, 0.587*bright, 0.114*bright);
    //to a index-able image to my hard drive? I tried  this string with imwrite and it just crashes. 
    char filename[80];
    cvWaitKey(10); 
    cout<< "new frame in window " <<buffer<<endl;  
    imshow("Video", imgH ); 
    imwrite(buffer, imgH); // this is not working!  
    c++;

}
//Exit

    if (ch == 27){ 

          cout << "esc key is pressed by user" << endl;
          return 0;  
       }
     }

    return 0;
}

how can I make imwrite work with a Mat video frame?

#include <opencv/cv.h>

In my code where I state if (c == 's')

how do I save Mat imgH = frame + Scalar(0.299bright, 0.587bright, 0.114*bright); to a index-able image to my hard drive? I tried imwrite and it just crashes any ideas what I'm missing?

 #include "opencv2/highgui/highgui.hpp"
 #include <iostream>
 #include <cstdlib>
 #include <windows.h> 

 using namespace cv;
 using namespace std;

 double Brightness;
 double Contrast ;
 double Saturation;
 double Gain;
 double Exposure; 

 char buffer[100]; 
 int i = 0; 
 int c = 1; 

 int main(int argc, char* argv[])
 {

     VideoCapture cap(0); // open the video camera no. 0


     if (!cap.isOpened()){
          cout << "Cannot open the video cam" << endl;
          return -1;
     }

     double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
     double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
     cap.set(CV_CAP_PROP_AUTO_EXPOSURE,0.0 );                // turn off auto exposure 

     // Get fixed Cam Properties

     Brightness = cap.get(CV_CAP_PROP_BRIGHTNESS); 
     Contrast   = cap.get(CV_CAP_PROP_CONTRAST );
     Saturation = cap.get(CV_CAP_PROP_SATURATION);
     Gain       = cap.get(CV_CAP_PROP_GAIN);
     Exposure   = cap.get(CV_CAP_PROP_AUTO_EXPOSURE ); 


     // Display Them 

     cout<<"===================================="<<endl;
     cout<<"Default Brightness -------> "<<Brightness<<endl;
     cout<<"Default Contrast----------> "<<Contrast<<endl;
     cout<<"Default Saturation--------> "<<Saturation<<endl;
     cout<<"Default Gain--------------> "<<Gain<<endl;
     cout<<"Default exp --------------> "<<Exposure<<endl; 
     cout<<"===================================="<<endl;


     // console adjustment for testing  

     cout << "\nFrame size : " << dWidth << " x " << dHeight << endl;
     int bright; 
     cout<< "\nbrightness level -100 - 100 " << endl; 
     cin>> bright;  
     cout <<"\nbrightness level: " <<bright <<endl; 

     namedWindow("Video"); //create a window called "MyVideo"


     for(;;) 
     {
         Mat frame;
         cap >> frame; 

         int x = 200;
         Sleep(x);           
         bool bFrame = cap.read(frame); // read a new frame from video
         int x = 200;
         Sleep(x); 

         Mat imgH = frame + Scalar(0.114*bright, 0.587*bright, 0.299*bright); // convert BGR to Luminance percieved 

         // imshow("Video", imgH ); //show the frame in "Video" window with adjusted luminescence value

         char ch =waitKey(30); 
         sprintf(buffer, "c:\\pics\\imge%d.jpg" , c); 


         // Camera Properties 

         if (ch == 'p'){ 
             cap.set(CV_CAP_PROP_SETTINGS , 1 ); 
         }

        if(ch== 's'){ 
     //how do I save  Mat imgH = frame + Scalar(0.299*bright, 0.587*bright, 0.114*bright);
     //to a index-able image to my hard drive? I tried  this string with imwrite and it just crashes. 
    char filename[80];
    cvWaitKey(10); 
     cout<< "new frame in window " <<buffer<<endl;  
     imshow("Video", imgH ); 
     imwrite(buffer, imgH); // this is not working!  
     c++;

}
//Exit

         


            // Exit
            if (ch == 27){ 
            cout << "esc key is pressed by user" << endl;
           return 0;  
        }
      }

     return 0;
 }

how can I make imwrite work with a Mat video frame?

#include <opencv/cv.h>

In my code where I state if (c == 's')

how do I save Mat imgH = frame + Scalar(0.299bright, 0.587bright, 0.114*bright); to a index-able image to my hard drive? I tried imwrite and it just crashes any ideas what I'm missing?

include "opencv2/highgui/highgui.hpp"

#include <iostream> #include <cstdlib> #include <windows.h>

 #include "opencv2/highgui/highgui.hpp"
    #include <iostream>
    #include <cstdlib>
    #include <windows.h> 

    using namespace cv;
 using namespace std;

 double Brightness;
 double Contrast ;
 double Saturation;
 double Gain;
 double Exposure; 

 char buffer[100]; 
 int i = 0; 
 int c = 1; 

 int main(int argc, char* argv[])
 {

     VideoCapture cap(0); // open the video camera no. 0


     if (!cap.isOpened()){
          cout << "Cannot open the video cam" << endl;
          return -1;
     }

     double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
     double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
     cap.set(CV_CAP_PROP_AUTO_EXPOSURE,0.0 );                // turn off auto exposure 

     // Get fixed Cam Properties

     Brightness = cap.get(CV_CAP_PROP_BRIGHTNESS); 
     Contrast   = cap.get(CV_CAP_PROP_CONTRAST );
     Saturation = cap.get(CV_CAP_PROP_SATURATION);
     Gain       = cap.get(CV_CAP_PROP_GAIN);
     Exposure   = cap.get(CV_CAP_PROP_AUTO_EXPOSURE ); 


     // Display Them 

     cout<<"===================================="<<endl;
     cout<<"Default Brightness -------> "<<Brightness<<endl;
     cout<<"Default Contrast----------> "<<Contrast<<endl;
     cout<<"Default Saturation--------> "<<Saturation<<endl;
     cout<<"Default Gain--------------> "<<Gain<<endl;
     cout<<"Default exp --------------> "<<Exposure<<endl; 
     cout<<"===================================="<<endl;


     // console adjustment for testing  

     cout << "\nFrame size : " << dWidth << " x " << dHeight << endl;
     int bright; 
     cout<< "\nbrightness level -100 - 100 " << endl; 
     cin>> bright;  
     cout <<"\nbrightness level: " <<bright <<endl; 

     namedWindow("Video"); //create a window called "MyVideo"


     for(;;) 
     {
         Mat frame;
         cap >> frame; 

         int x = 200;
         Sleep(x);           
            bool bFrame = cap.read(frame); // read a new frame from video
            int x = 200;
            Sleep(x); 

             Mat imgH = frame + Scalar(0.114*bright, 0.587*bright, 0.299*bright); // convert BGR to  Luminance percieved 

         // imshow("Video", imgH ); //show the frame in "Video" window with adjusted luminescence value

         char ch =waitKey(30); 
         sprintf(buffer, "c:\\pics\\imge%d.jpg" , c); 


         // Camera Properties 

         if (ch == 'p'){ 
         cap.set(CV_CAP_PROP_SETTINGS , 1 ); 
      }

      // Save Image

     if(ch== 's'){ 
     //how do I save  Mat imgH = frame + Scalar(0.299*bright, 0.587*bright, 0.114*bright);
     //to a index-able image to my hard drive? I tried  this string with imwrite and it just crashes. 
     cvWaitKey(10); 
     cout<< "new frame in window " <<buffer<<endl;  
     imshow("Video", imgH ); 
     imwrite(buffer, imgH); // this is not working!  
     c++;
 

}

        // Exit
         if (ch == 27){ 
         cout << "esc key is pressed by user" << endl;
         return 0;  
        }
      }

     return 0;
 }

how can I make imwrite work with a Mat video frame?

#include <opencv/cv.h>

In my code where I state if (c == 's')

how do I save Mat imgH = frame + Scalar(0.299bright, 0.587bright, 0.114*bright); to a index-able image to my hard drive? I tried imwrite and it just crashes any ideas what I'm missing?

include "opencv2/highgui/highgui.hpp"

#include <opencv/cv.h> 
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
 #include <cstdlib>
 #include <windows.h> 

 using namespace cv;
using namespace std;
double Brightness;
double Contrast ;
Contrast;
double Saturation;
double Gain;
double Exposure;
char buffer[100];
buffer[100];
int  i = 0;
0;
int  c = 1;
//const std::string fileName = "c://pics//image%u.jpg";

int main(int argc, char* argv[])
{
VideoCapture cap(0); // open the video camera no. 0
  if (!cap.isOpened()){
cout << "Cannot open the video cam" << endl;
return -1;
}
 
double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
cap.set(CV_CAP_PROP_AUTO_EXPOSURE,0.0 ); // turn off auto exposure
// Get fixed Cam Properties
Brightness = cap.get(CV_CAP_PROP_BRIGHTNESS);
Contrast = cap.get(CV_CAP_PROP_CONTRAST );
Saturation = cap.get(CV_CAP_PROP_SATURATION);
Gain = cap.get(CV_CAP_PROP_GAIN);
Exposure = cap.get(CV_CAP_PROP_AUTO_EXPOSURE );
// Display Them
cout<<"===================================="<<endl;
cout<<"Default Brightness -------> "<<Brightness<<endl;
cout<<"Default Contrast----------> "<<Contrast<<endl;
cout<<"Default Saturation--------> "<<Saturation<<endl;
cout<<"Default Gain--------------> "<<Gain<<endl;
cout<<"Default exp --------------> "<<Exposure<<endl;
cout<<"===================================="<<endl;
// console adjustment for testing
cout << "\nFrame size : " << dWidth << " x " << dHeight << endl;
int bright;
cout<< "\nbrightness level -100 - 100 " << endl;
cin>> bright;
cout <<"\nbrightness level: " <<bright <<endl;
namedWindow("Video"); //create a window called "MyVideo"
for(;;)
{
  Mat frame;
  cap >> frame;  
int x = 200;
Sleep(x);  
Mat imgH = frame + Scalar(0.0722*bright, 0.7152*bright, 0.7152*bright); // convert BGR to Luminance set to color space
// Mat imgH = frame + Scalar(0.114*bright, 0.587*bright, 0.299*bright); // convert BGR to  Luminance percieved
 // 
// imshow("Video", imgH ); //show the frame in "Video" "MyVideo" window with adjusted luminescence value
contrast and brightness

char ch =waitKey(30);
sprintf(buffer, "c:\\pics\\imge%d.jpg" , c);
// Camera Properties "C:\\pics\\image%d.jpg" ,c);
// cvWaitKey(10);
//save image frmae 
if (ch == 'p'){
cap.set(CV_CAP_PROP_SETTINGS , 1 );
}
// Save Image
if(ch== 's'){
//how do I save Mat imgH = frame + Scalar(0.299*bright, 0.587*bright, 0.114*bright);
//to a index-able image to my hard drive? I tried this string with imwrite and it just crashes.
's'){
 cvWaitKey(10);
  cout<< "new frame in window " <<buffer<<endl;
 imshow("Video", imgH );
);
 imwrite(buffer, imgH); //  <-- this is not working!
c++;

}

        // Exit
working die in a hole!!!
c++ ;
}
// Camera Properties
if (ch == 'p'){
cap.set(CV_CAP_PROP_SETTINGS , 1 );
}
//Exit
 if (ch == 27){
  cout << "esc key is pressed by user" << endl;
  return 0;
}
}
return 0;
}

how can I make imwrite work with a Mat video frame?

In my code where I state if (c == 's')

how do I save Mat imgH = frame + Scalar(0.299bright, 0.587bright, 0.114*bright); to a index-able image to my hard drive? I tried imwrite and it just crashes any ideas what I'm missing?

#include <opencv/cv.h> 
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <cstdlib>
#include <windows.h> 

using namespace cv;
using namespace std;

double Brightness;
double Contrast;
double Saturation;
double Gain;
double Exposure; 

char buffer[100];
int  i = 0;
int  c = 1; 
//const std::string fileName = "c://pics//image%u.jpg";

int main(int argc, char* argv[])
{

    VideoCapture cap(0); // open the video camera no. 0



    if (!cap.isOpened()){
         cout << "Cannot open the video cam" << endl;
         return -1;
    }


    double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
    double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
    cap.set(CV_CAP_PROP_AUTO_EXPOSURE,0.0 );                // turn off auto exposure 

    // Get fixed Cam Properties

    Brightness = cap.get(CV_CAP_PROP_BRIGHTNESS); 
    Contrast   = cap.get(CV_CAP_PROP_CONTRAST );
    Saturation = cap.get(CV_CAP_PROP_SATURATION);
    Gain       = cap.get(CV_CAP_PROP_GAIN);
    Exposure   = cap.get(CV_CAP_PROP_AUTO_EXPOSURE ); 


    // Display Them 

    cout<<"===================================="<<endl;
    cout<<"Default Brightness -------> "<<Brightness<<endl;
    cout<<"Default Contrast----------> "<<Contrast<<endl;
    cout<<"Default Saturation--------> "<<Saturation<<endl;
    cout<<"Default Gain--------------> "<<Gain<<endl;
    cout<<"Default exp --------------> "<<Exposure<<endl; 
    cout<<"===================================="<<endl;


    // console adjustment for testing  

    cout << "\nFrame size : " << dWidth << " x " << dHeight << endl;
    int bright; 
    cout<< "\nbrightness level -100 - 100 " << endl; 
    cin>> bright;  
    cout <<"\nbrightness level: " <<bright <<endl; 

    namedWindow("Video"); //create a window called "MyVideo"


    for(;;) 
    {

        Mat frame;

        cap >> frame;   

        int x = 200;
        Sleep(x); 

        Mat imgH = frame + Scalar(0.0722*bright, 0.7152*bright, 0.7152*bright); // convert BGR to Luminance set to color space 
        // Mat imgH = frame + Scalar(0.114*bright, 0.587*bright, 0.299*bright); // convert BGR to Luminance percieved 


    //   imshow("Video", imgH ); //show the frame in "MyVideo" window with adjusted contrast and brightness 


        char ch =waitKey(30); 
        sprintf(buffer, "C:\\pics\\image%d.jpg" ,c); 
    //  cvWaitKey(10); 


        //save image frmae frame 

        if (ch == 's'){


        cvWaitKey(10); 
        cout<< "new frame in window " <<buffer<<endl;  
        imshow("Video", imgH );
        imwrite(buffer, imgH); //  <-- this is not working die in a hole!!!
working!
        c++ ;
        }

        // Camera Properties 

        if (ch == 'p'){ 
            cap.set(CV_CAP_PROP_SETTINGS , 1 ); 
        }


        //Exit

        if (ch == 27){ 

            cout << "esc key is pressed by user" << endl;

            return 0;  
       }
     }

    return 0;
}