Monday, August 22, 2011

Episode_16_RGB_Color_on_Form_Application


Sometimes we need how to make RGB on Form Application or making 3 channel to 1 channel. Difficult ?? I don't think so.

Well, this is request for my freind that give me idea to write next Episode. I need your help (Reader) to give me a comment if there is something wrong with my source code, so I can correctly as soon as possible.As in Episode 4, I just add a little trick.

For Blue Color.

private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
       frame = cvQueryFrame(capture);

       cvCvtColor(frame,img,CV_BGR2GRAY);
       cvMerge(NULL , img, img, NULL, img2);  //Composes a multi-channel array from several single-channel arrays or inserts a single channel into the array.

       pictureBox1->Image  = gcnew    //replacement of cvShowImage
       System::Drawing::Bitmap(img2->width,img2->height,img2->widthStep,
       System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr) img2->imageData);
       pictureBox1->Refresh();
   }
For Green Color.
private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
       frame = cvQueryFrame(capture);

       cvCvtColor(frame,img,CV_BGR2GRAY);
       cvMerge(img , NULL, img, NULL, img2);  //Composes a multi-channel array from several single-channel arrays or inserts a single channel into the array.

       pictureBox1->Image  = gcnew    //replacement of cvShowImage
       System::Drawing::Bitmap(img2->width,img2->height,img2->widthStep,
       System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr) img2->imageData);
       pictureBox1->Refresh();
   }
For Red Color.
private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
        frame = cvQueryFrame(capture);

        cvCvtColor(frame,img,CV_BGR2GRAY);
        cvMerge(img , img, NULL, NULL, img2);  //Composes a multi-channel array from several single-channel arrays or inserts a single channel into the array.

        pictureBox1->Image  = gcnew    //replacement of cvShowImage
        System::Drawing::Bitmap(img2->width,img2->height,img2->widthStep,
        System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr) img2->imageData);
        pictureBox1->Refresh();
    }
Yahuiii.. Easy isn't? You can make other colors with changing cvMerge and tell me what other colors you can get it. Ok

0 comments:

Post a Comment