Load, Display and Save an image


Mat imread(const string& filename, intflags=1 )
Parameters:
  • filename – Name of file to be loaded.
  • flags –Flags specifying the color type of a loaded image:
    • CV_LOAD_IMAGE_ANYDEPTH - return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
    • CV_LOAD_IMAGE_COLOR(>0) - If set, always convert image to the color one
    • CV_LOAD_IMAGE_GRAYSCALE (0)- If set, always convert image to the grayscale one
    • CV_LOAD_IMAGE_UNCHANGED (<0) loads the image as is (including the alpha channel if present)
bool imwrite(const string& filename, InputArray img, const vector<int>&params=vector<int>() )
Parameters:
  • filename – Name of the file.
  • image – Image to be saved.
  • params – Format-specific save parameters encoded as pairs paramId_1, paramValue_1, paramId_2, paramValue_2, ... . The following parameters are currently supported:
    • For JPEG, it can be a quality (CV_IMWRITE_JPEG_QUALITY ) from 0 to 100 (the higher is the better). Default value is 95.
    • For PNG, it can be the compression level (CV_IMWRITE_PNG_COMPRESSION) from 0 to 9. A higher value means a smaller size and longer compression time. Default value is 3.
    • For PPM, PGM, or PBM, it can be a binary format flag (CV_IMWRITE_PXM_BINARY ), 0 or 1. Default value is 1.
void imshow(const string& winname, InputArray mat)

Parameters:
  • winname – Name of the window.
  • image – Image to be shown.

Steps:

  1. Load image using imread().
  2. Display image using namedWindow() and imshow().
  3. Save the image using imwrite().
  4. Wait for keyboard button press using waitKey().

Example:

--------------
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main( )
{

       Mat image;

       // LOAD image
       image = imread("image1.jpg", CV_LOAD_IMAGE_COLOR);   // Read the file "image.jpg".
              //This file "image.jpg" should be in the project folder.
              //Else provide full address : "D:/images/image.jpg"

       if(! image.data )  // Check for invalid input
       {
              cout <<  "Could not open or find the image" << std::endl ;
              return -1;
       }

       //DISPLAY image
       namedWindow( "window", CV_WINDOW_AUTOSIZE ); // Create a window for display.
       imshow( "window", image ); // Show our image inside it.

       //SAVE image
       imwrite("result.jpg",image);// it will store the image in name "result.jpg"

       waitKey(0);                       // Wait for a keystroke in the window
       return 0;
}
--------------

Sources:
http://docs.opencv.org/doc/tutorials/introduction/display_image/display_image.html

37 comments:

  1. Replies
    1. Learn Opencv By Examples: Load, Display And Save An Image >>>>> Download Now

      >>>>> Download Full

      Learn Opencv By Examples: Load, Display And Save An Image >>>>> Download LINK

      >>>>> Download Now

      Learn Opencv By Examples: Load, Display And Save An Image >>>>> Download Full

      >>>>> Download LINK 2J

      Delete
  2. It is a really nice blog. Super practical and easy to learn. Thanks for sharing.

    ReplyDelete
  3. Finally something that expains imwrite shortly and easy! Thank you very much! :)

    ReplyDelete
  4. Nice blog. Is it possible to save the image in other formats?

    ReplyDelete
  5. How if i have work with openCV in Matlab ??

    ReplyDelete
  6. Thank you sir. This is very helpful!

    ReplyDelete
  7. first time using opencv, nothing work. Defined paths for include and libs did not recognized and many errors in compilation. Checked 4 times settings with document and everything is ok but dont know. Using Visualk Studio 2015 community.

    ReplyDelete
    Replies
    1. I do have a same problem. Help me if u get that idea please.

      Delete
    2. Set environment variables, set parhs for libs and bin in your working editor(netbeans, vs, codeblocks,dev c++ etc)

      Delete
  8. We can load any image file in Opencv C++, python or android. Its steps are very simple and easy.We can show any format of image in opencv like JPG and PNG. We can use three functions from opencv to show , load and save frames imread(), imshow() and imwrite().

    Mat cv::imread ( const String & filename, int flags = IMREAD_COLOR ) // Read image

    void cv::imshow ( Window Name , Mat Object to show ) // Show image

    Void cv::imwrite ( filename, InputArray img) // Write frame in hard drive

    Download complete code of imread function in C++ from opencvcraze.com

    ReplyDelete
  9. Hi, i have output says that cannot find or open the pdb file. How can i solve it?

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. Its very useful for begginers...Thanks

    ReplyDelete
  12. how to read multiple images from a folder?

    ReplyDelete
  13. Hello sir,how to read images from a folder numbered as img_1.png, img_2.png ... img_137.png....Thanks

    ReplyDelete
  14. Our online tool allows you to convert PDF documents to JPG images for free. No downloads required.

    If you want more information to click here Convert pdf to png

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. The author provides a very detailed method of Load, Display and Save an image, let me understand how to implement the pdf to image method, and gather more basic functions of pdf, thank you very much.

    ReplyDelete
  17. Your blog post is really helpful to get information on how to convert jpg to vector. Good job mate..!

    ReplyDelete
  18. Your blog posts are more interesting and impressive. I think there are many people like and visit it regularly, including me. I appreciate your own position and I will be sure to come back here

    ReplyDelete
  19. Most of time it is hard to find something on internet but when you do you feel like a pro.

    ReplyDelete
  20. As a result of some quality work and informative thoughts, I was blown away after reading this article. My gratitude and best wishes go out to the writer! I have another thing for you: the WPM typing test. Test your typing accuracy with this test to find out how many words you typed in a minute. Various typing modes are included in the test. Enjoy this feature and boost your typing speed.

    ReplyDelete
  21. Learn Opencv By Examples: Load, Display And Save An Image >>>>> Download Now

    >>>>> Download Full

    Learn Opencv By Examples: Load, Display And Save An Image >>>>> Download LINK

    >>>>> Download Now

    Learn Opencv By Examples: Load, Display And Save An Image >>>>> Download Full

    >>>>> Download LINK UP

    ReplyDelete
  22. สล็อตเครดิตฟรี โปรโมชั่นเยอะ เว็บสล็อตที่ตอบโจทย์มากที่สุด ต้องยกให้ ambbets.com เว็บตรง สล็อตออนไลน์เว็บใหญ่ที่สุด ส่งตรงจากต่างประเทศ เกมสล็อตลิขสิทธิ์เเท้ ไม่ผ่านเอเย่นต์คนกลาง ปลอดภัย จ่ายเต็ม 100% ฝากถอนไม่มีขั้นต่ำ รวดเร็วด้วยระบบ AUTO มีทีมงานพร้อมให้บริการตลอดการเดิมพัน เริ่มกับเราด้วยงบเพียง 1 บาทเท่านั้น เปิดให้บริการ 24 ชั่วโมง.

    ReplyDelete
  23. Thanks for sharing the facts. You truly impressed me by this post of yours. And what exactly is additional commendable will be the authenticity in the content material. startup tips

    ReplyDelete
  24. Wow! These are gorgeous! This is so Pretty Designing and a wonderful look. It is such a fabulous idea, I will trying made this design. Thanks For sharing the tutorial. Great Work.

    ReplyDelete
  25. This is a great article! I found your article to be very informative and well-written. Thank you for sharing your knowledge on this topic! Convert JPEG To PNG Online

    ReplyDelete
  26. Looking for premium custom embroidery in the USA? True Digitizing offers top-notch embroidery solutions, elevating your branding and personalization needs. With precision and style, we bring your designs to life. Explore our diverse range of embroidery services today.

    ReplyDelete
  27. Appliqué embroidery has a rich history that spans cultures and centuries. Its timeless appeal lies in the ability to combine different fabrics, colors, and textures to craft unique and eye-catching designs. From delicate floral patterns to bold geometric shapes, the possibilities are limited only by your imagination. A1 Digitizing understands the significance of preserving this art form and brings it to life in the digital realm.

    ReplyDelete
  28. When it comes to embroidery digitizing, True Digitizing stands out as the go-to choice. Our expert team ensures precision and quality in every design. With True Digitizing, your embroidery projects will shine with intricate details and vibrant colors. Trust us for top-notch embroidery digitizing services that bring your creations to life.

    ReplyDelete
  29. Heeled mules complement flares, a trendy fusion of comfort and style.
    regards: shoes to wear with flare jeans

    ReplyDelete