1.
// readbmp.cpp : Defines the entry point for the console application.
2.
//
3.
4.
#include "stdafx.h"
5.
#include
6.
7.
#include "ipl.h"
8.
#include "cv.h"
9.
//#include "_cv.h"
10.
//#include "vlgrfmts.h"
11.
12.
//-----------------------------
13.
UTILITY FUNCTIONS
14.
//
15.
// Read in a BMP and convert it into an IPL
16.
// fin The file name of the BMP with path
17.
// plannar If set, convert the image to plannar
18.
// flip If set, mirror the image around the horizontal axis, set
19.
// IPL_ORIGIN_BL)
20.
IplImage * readBMP2IPL(
char
*fin,
int
plannar = 0,
int
flip = 0)
21.
{
22.
int
filter;
23.
int
width=0,height=0,color=55,hdr_ret=0,close_ret = 0,rd_ret = 0;
24.
IplImage *I;
25.
filter = gr_fmt_find_filter(fin );
//Get file type
26.
hdr_ret = gr_fmt_read_header( filter, &width, &height, &color );
//image
params
27.
I = cvCreateImageHeader( cvSize(width, height), IPL_DEPTH_8U, 3);
//crea
te image header
28.
I->align = IPL_ALIGN_QWORD;
//fix the problem that cvCreateImage uses al
ign 4
29.
I->depth != IPL_DEPTH_32F ? iplAllocateImage( I, 0, 0 ) :iplAllocateImag
eFP( I, 0, 0 );
30.
rd_ret = gr_fmt_read_data(filter, I->imageData, I->widthStep, color);
//
read in the data, origin TL
31.
close_ret = gr_fmt_close_filter( filter );
32.
if
(plannar)
//If plannar order desired, turn it into plannar order
33.
{
34.
IplImage *Ip = iplCreateImageHeader(3, 0, IPL_DEPTH_8U,
"RGB"
,
"BGR"
,
IPL_DATA_ORDER_PLANE, I->origin, IPL_ALIGN_QWORD, width, height, NULL,NULL,N
ULL,NULL);
35.
iplAllocateImage(Ip, 0,0);
36.
iplConvert(I,Ip);
37.
cvReleaseImage( &I );