全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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, /image p arams 27. I = cvCreateImageHeader( cvSize(width, height), IPL_DEPTH_8U, 3); /creat e image header 28. I- align = IPL_ALIGN_QWORD; /fix the problem that cvCreateImage uses align 4 29. I- depth != IPL_DEPTH_32F ? iplAllocateImage( I, 0, 0 ) :iplAllocateImageFP( 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,NULL,NULL); 35. iplAllocateImage(Ip, 0,0); 36. iplConvert(I,Ip); 37. cvReleaseImage( 38. I = Ip; 39. 40. if(flip) /User wants IPL_ORIGIN_BL 41. 42. iplMirror(I, I, 0); /flipporuni 43. I-origin = IPL_ORIGIN_BL; 44. 45. return I; 46. 47. 48. / 49. / Write IPL image to disk as a BMP image (not optimized but step by step sim plistic) 50. / fout Pathfilename to write to 51. / I IPL image to be written 52. / 53. / Image fomat may be any of: 54. / dataOrder Plane or Pixel 55. / 1 channel (GRAY) or 3 (RGB) 56. / 8U, 8S, 32F 57. / Origin TL or BL (if BL, image is flipped to conform to TL bmps) 58. / 59. / If image is not RGB or GRAY, RGB is simply imposed on the Image. E.g. if i ts YUV, 60. / the image will be stored as BGR with B=Y, G=U, and R=V 61. void writeIPL2BMP(char *fout, IplImage *I) 62. 63. IplImage *Isav,*Itmp; 64. Isav = iplCloneImage(I); 65. /Convert to pixel order if needed 66. if(I-dataOrder = IPL_DATA_ORDER_PLANE) 67. 68. Itmp = iplCreateImageHeader(I-nChannels, 69. I-alphaChannel, I-depth, I-colorModel, 70. I-channelSeq, IPL_DATA_ORDER_PIXEL, I-origin, 71. I-align, 72. I-width, I-height, NULL, NULL,NULL,NULL); 73. if(I-depth = IPL_DEPTH_32F) 74. iplAllocateImageFP(Itmp, 1,0.0); 75. else 76. iplAllocateImage(Itmp, 1,0); 77. iplConvert(I, Itmp); 78. iplDeallocate (I, IPL_IMAGE_ALL); 79. I = Itmp; 80. 81. /Image is now pixel order. Convert to 8U if needed. 82. if(I-depth = IPL_DEPTH_8S) 83. I-depth = IPL_DEPTH_8U; 84. else if(I-depth = IPL_DEPTH_32F) 85. 86. float min,max; 87. iplMinMaxFP (I, 88. Itmp = iplCreateImageHeader(I-nChannels, 89. I-alphaChannel, IPL_DEPTH_8U, I-colorModel, 90. I-channelSeq, IPL_DATA_ORDER_PIXEL, I-origin, 91. I-align, 92. I-width, I-height, NULL, NULL,NULL,NULL); 93. iplAllocateImage(Itmp, 1,0); 94. if(min = max) max = (float)(min + 1.0); 95. iplScaleFP (I, Itmp, min, max); 96. iplDeallocate (I, IPL_IMAGE_ALL); 97. I = Itmp; 98. 99. /Image is now pixel order, 8U. Convert to RGB if needed 100. if(I-nChannels = 3) 101. 102. strcpy(I-colorModel,“RGB“); 103. strcpy(I-channelSeq,“BGR“); 104. 105. else if(I-nChannels = 1) 106. 107. Itmp = iplCreateImageHeader(3, 108. I-alphaChannel, IPL_DEPTH_8U, “RGB“, 109. “BGR“, IPL_DATA_ORDER_PIXEL, I-origin, I-align, 110. I-width, I-height, NULL, NULL,NULL,NULL); 111. iplAllocateImage(Itmp, 1,0); 112. iplGrayToColor (I, Itmp, 1.0, 1.0, 1.0); 113. iplDeallocate (I, IPL_IMAGE_ALL); 114. I = Itmp; 115. 116. else 117. return; 118. /Image is now pixel order, 8U, RGB, flip it if the origin is BL 119. if(I-origin = IPL_ORIGIN_BL) 120. 121. iplMirror(I, I, 0); 122. 123. /FINALLY, WRITE THE IMAGE: 124. int write_ret = gr_fmt_write_image( I-imageData, I-widthStep, 125. I-width, I-height, I-colorModel0 =R?1:0,fout, “bmp“); 126. /Return image to its original state 127. iplDeallocate(I, IPL_IMAGE_ALL); 128. I = Isav; 129. 130. 131./- 132. 133.void main() 134. 135. IplImage * input_img=NULL; 136. int plannar=0; 137. int flip=0; 138. char fin=“circles.bmp“; 139. char fout=“result.bmp“; 140. 141. 142. /作一些声明 143. CvMemStorage *storage; 144. int header_size, i, count,length, width; 145. CvSeq *contour; 146. CvBox2D * myBox; /用于画圆和椭圆 147. CvPoint *PointArray; 148. CvPoint2D32f *PointArray32f; 149. CvPoint myCenter; 150. 151. / 分配内存 152. myBox= (CvBox2D *) malloc(sizeof(CvBox2D); 153. header_size = sizeof(CvContour); 154. storage = cvCreateMemStorage (1000); / For FindContours. 155. 156. / 读入图象 input_img 并转换为 IPLIMAGE 格式 157. /已经定义 char fin=“circles.bmp“; 158. input_img=readBMP2IPL(fin,plannar, flip); 159. 160. coutnChannelscenter.x; 162. myCenter.y = (int) myBox-center.y; 163. 164. /HEIGHT AND WITH (THE 2 AXES OF THE ELLIPSE) 165. length =(int)myBox-size.height; 166. width = (int)myBox-size.width; 167. 168. /AND THE ANGLE 169. float myAngle= myBox-angle; 170. 171. / 检查这个椭圆是否在图象内 172. if (myCenter.x 0) 176. 177. /画椭圆 178. cvEllipse(input_img, 179. myCenter, 180. cvSize (int)width/2,(int)length/2) , 181. myBox-angle, 182. 0,360,RGB(255,0,255),1); 183. 184. 185. 186. free(PointArray32f ); 187. fre
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025工业视觉检测技术突破与行业渗透率分析
- 2025工业互联网平台分析及制造业转型与产业基金配置报告
- 2025大健康产业融合发展现状及未来增长点研究报告
- 2025多光谱成像设备市场发展分析及前景趋势与投资潜力研究报告
- 2025卫星互联网组网技术突破与商业航天投资热点
- 2025半导体光刻胶材料技术创新与下游需求市场预测研究报告
- 美国区域代理协议合同
- 美食学徒中介合同范本
- 衣服品牌供货合同范本
- 美食会所会员合同范本
- 锂电池生产中的潜在安全风险及其控制措施
- 《中国在全球治理体系中的地位》课件
- 长城汽车公司管理制度
- GB/T 24477-2025适用于残障人员的电梯附加要求
- 部队防失泄密教育课件
- GB/T 45355-2025无压埋地排污、排水用聚乙烯(PE)管道系统
- 医药销售团队工作职责和分工
- 2025年音视频面试题及答案
- 血管壁的一般结构职业教育医学检验专业教学课件
- 中国广电笔试试题及答案
- 汉日翻译之理解当代中国(山东联盟)知到智慧树章节测试课后答案2024年秋青岛滨海学院
评论
0/150
提交评论