0% found this document useful (0 votes)
29 views

#Include #Include #Include Int Int: "Stdafx.h" "CV.H" "Highgui.h"

This C++ code loads an image file, displays it in a window, and adds text to the image before displaying it again. It first loads an image from the file path given, displays it in a window, and waits for a key press to close the window. It then loads another image, initializes a font, adds "Hello World!" text to the image in white, displays the modified image in a second window, and waits for a key press before closing the window and releasing resources.

Uploaded by

sri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

#Include #Include #Include Int Int: "Stdafx.h" "CV.H" "Highgui.h"

This C++ code loads an image file, displays it in a window, and adds text to the image before displaying it again. It first loads an image from the file path given, displays it in a window, and waits for a key press to close the window. It then loads another image, initializes a font, adds "Hello World!" text to the image in white, displays the modified image in a second window, and waits for a key press before closing the window and releasing resources.

Uploaded by

sri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

// show_image.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"
#include "cv.h"
#include "highgui.h"

int _tmain(int argc, _TCHAR* argv[])


{
IplImage *image = 0;
image = cvLoadImage( "C:/Program Files/OpenCV/samples/c/2.jpg", 1 );
if( image )
{
cvNamedWindow( "Show", 1 );
cvShowImage( "Show", image );
printf( "Press any key to exit\n");
cvWaitKey(0);
cvDestroyWindow("result");
}
else
fprintf( stderr, "Error reading image\n" );
return 0;
}

#include <stdio.h>
#include "cv.h"
#include "highgui.h"

int main(int argc, char** argv)


{
IplImage *img = cvLoadImage("2.jpg", CV_LOAD_IMAGE_COLOR);

/* initialize font and add text */


CvFont font;
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0, 0, 1, CV_AA);
cvPutText(img, "Hello World!", cvPoint(10, 130), &font,
cvScalar(255, 255, 255, 0));

/* display the image */


cvNamedWindow("image", CV_WINDOW_AUTOSIZE);
cvShowImage("image", img);
cvWaitKey(0);
cvDestroyWindow("image");
cvReleaseImage( &img );

return 0;
}

You might also like