zoukankan      html  css  js  c++  java
  • How to Display Image In Picturebox in VC++ from Iplimage and Mat

    Introduction

    This tip/trick will be useful to OpenCV programmers, who wish to use Windows Form application under Visual C++. This tip helps programmers to use Windows function with OpenCV library. The following tip shows how to assigniplimage and mat variable to picturebox image.

    Assign Iplimage to Picturebox Image

    In this part, it shows how to assign iplimage to picturebox image. First of all, declare the frame pointer. Iplimagetype.

    Declare Iplimage variable:

    IplImage* frame; 

    Here. Create new Bitmap image from frame properties like widthheightwidthstep. Set image data from frameimagedata.

    Process the PictureBox.

    pictureBox1->Image  = gcnew System::Drawing::Bitmap
    (frame->width,frame->height,frame->widthStep,
    System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr) frame->imageData);
    pictureBox1->Refresh(); 

    Assign Mat to Picturebox Image

    In this part, it shows how to assign Mat to picturebox image. First of all, declare the frameDetected variable, Mattype.

    Declare Mat variable.

    Mat frameDetected; 

    Here. Create graphics of picturebox. Then create new Bitmap image from frameDetected properties like cols, rows, step. Then create Rectangle with and with value and width and height with picturebox height,width respectively. Then rectangle assign to previous initialized graphics object.

    Process the PictureBox:

    System::Drawing::Graphics^ graphics2 = pictureBox3->CreateGraphics();
    System::IntPtr ptr2(frameDetected.ptr());
    System::Drawing::Bitmap^ b2  = gcnew System::Drawing::Bitmap(frameDetected.cols,
    frameDetected.rows,frameDetected.step,System::Drawing::Imaging::PixelFormat::Format24bppRgb,ptr2);
    System::Drawing::RectangleF rect2(0,0, pictureBox3->Width,pictureBox3->Height);
    graphics2->DrawImage(b2,rect2);  

    Points of Interest

    • Learn how to assign iplimage to picturebox image
    • Learn how to assign Mat to picturebox image

    References

    1. http://opencv.org/
    2. http://en.wikipedia.org/wiki/OpenCV
    3. http://docs.opencv.org/

    Sorry

    Sorry for my English. If you notice errors or can suggest a more correct version, please let me know.

  • 相关阅读:
    MongoDB
    Django配置实现数据库读写分离
    基于scrapy-redis的分布式爬虫
    增量式爬虫
    Pyhton网络爬虫之CrawlSpider
    Scrapy 之如何发送post请求
    Scrapy 之settings配置
    Scrapy 实现爬取多页数据 + 多层url数据爬取
    Scrapy 框架入门简介
    redis操作总结
  • 原文地址:https://www.cnblogs.com/FredCong/p/3829319.html
Copyright © 2011-2022 走看看