智能车制作

 找回密码
 注册

扫一扫,访问微社区

查看: 2112|回复: 1
打印 上一主题 下一主题

[采集类] 摄像头采集问题

[复制链接]

4

主题

26

帖子

0

精华

高级会员

Rank: 4

积分
558
威望
402
贡献
66
兑换币
0
注册时间
2011-3-3
在线时间
45 小时
跳转到指定楼层
1#
发表于 2011-6-11 09:33:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1贡献
我是个菜鸟,图像搞了很久都搞不出来,求助各位大哥!!
这是我根据上位机通信协议写的采集程序,但是什么都看不到,麻烦大家帮我看看。
  1. #include <hidef.h>
  2. #include <MC9S12XS128.h>
  3. /*************宏定义****************************/
  4. #define LINE_MAX 75 // 每行采集的点数,即列数
  5. #define ROW_MAX 95 // 采集到的行数

  6. /*************变量定义**************************/
  7. uchar a,b,c,temp;

  8. unsigned char Image[ROW_MAX][LINE_MAX];//图像数据
  9. uchar John[ROW_MAX][LINE_MAX];
  10. uchar row1; //图像数组行数
  11. uchar rowjd;
  12. uchar counter2;
  13. uint i;
  14. uint j;
  15. uint k;
  16. uint h;
  17. uint l;
  18. uint sign;
  19. static unsigned char space=0; //记录行中断
  20. /***************变量及数组初始化****************/
  21. void InitVariable(void)
  22. {
  23. counter2=0;
  24. // k=550;
  25. for(i=0;i<ROW_MAX;i++)
  26. for(j=0;j<LINE_MAX;j++)
  27. Image[i][j]=0;
  28. }

  29. /*************主频设置**************************/
  30. void Busclock(void) //05,01 48MHz 06,01 56MHz 07,01 64MHz 08,01 72MHz
  31. {
  32. CLKSEL=0x00;
  33. PLLCTL_PLLON=1;
  34. SYNR=0xC0 | 0x08;
  35. REFDV=0xC0 | 0x01;
  36. POSTDIV=0x00;
  37. _asm(nop);
  38. _asm(nop);
  39. while(!(CRGFLG_LOCK==1));
  40. CLKSEL_PLLSEL =1;
  41. }

  42. /*************定时器初始化***********************/
  43. void InitEct(void)
  44. {
  45. TIOS=0x00; //外部输入捕捉0,1通道
  46. TCTL4=0x09; //通道0上升沿触发,通道1下降沿触发
  47. TSCR1=0x80;
  48. TIE_C1I = 1; //场中断使能
  49. TIE_C0I = 1; //行中断使能
  50. }
  51. unsigned char SciRead()
  52. {
  53. if(SCI0SR1_RDRF==1) //表明数据从位移寄存器传输到SCI 数据寄存器
  54. {
  55. SCI0SR1_RDRF=1; //读取数据寄存器会将RDRF 清除重新置位
  56. return SCI0DRL; //返回数据寄存器的数据
  57. }
  58. }

  59. /*************串口初始化*************************/
  60. void SciInit()
  61. {
  62. SCI0BD=52; //9600bps Baud Rate=BusClock/(16*SCIBD)
  63. SCI0CR1=0; //正常8 位模式,无奇偶校验
  64. SCI0CR2=0X2C; //发送允许接受中断允许
  65. }

  66. /*************I/O初始化*************************/
  67. void InitIoport(void)
  68. {
  69. DDRA=0x00;
  70. }
  71. /**************发射端程序************************/
  72. void SciTx(uchar text)
  73. {
  74. while (!(SCI0SR1&0x80));
  75. SCI0DRH=0;
  76. SCI0DRL=text;
  77. }
  78. /**************发射端程序************************/
  79. void SciTxs(uchar *s)
  80. {
  81. while (!(SCI0SR1&0x80));
  82. SCI0DRH=0;
  83. while(*s!='\0'){

  84. SCI0DRL=*s;

  85. s++;
  86. }
  87. }

  88. /**************延时******************************/
  89. void Delay(int delay)
  90. { int i,j;
  91. for(i=0;i<delay;i++)
  92. {for(j=0;j<500;j++)
  93. asm nop;
  94. }
  95. }

  96. /*************主函数*****************************/
  97. void main()
  98. {


  99. DisableInterrupts;
  100. Busclock();
  101. InitEct();
  102. SciInit();
  103. InitVariable();
  104. InitIoport();
  105. EnableInterrupts;
  106. Delay(4000);
  107. for(;;)
  108. {
  109. }
  110. }
  111. /**********场中断处理******************************************/
  112. #pragma CODE_SEG __NEAR_SEG NON_BANKED
  113. void interrupt 9 Port1_interrupt(void)
  114. {
  115. TFLG1=0x02;
  116. TIE_C0I = 1; //开行中断
  117. row1 = 0;
  118. rowjd=0;
  119. sign=0;

  120. if(counter2==1)
  121. {
  122. TIE_C1I = 0;
  123. TIE_C0I = 0;
  124. }
  125. counter2++;
  126. }
  127. /**************行中断采集*************************/
  128. #pragma CODE_SEG __NEAR_SEG NON_BANKED //开始一段赋值是起延时的作用,调中心是加减就行了
  129. void interrupt 8 Port0_interrupt(void)
  130. {
  131. TFLG1=0x01; //清除行中断标志
  132. rowjd++;
  133. if(rowjd%2==0)
  134. {
  135. Image[row1][0] = PORTA;
  136. Image[row1][0] = PORTA;
  137. Image[row1][0] = PORTA;
  138. Image[row1][0] = PORTA;
  139. Image[row1][0] = PORTA;
  140. Image[row1][0] = PORTA;
  141. Image[row1][0] = PORTA;
  142. Image[row1][0] = PORTA;
  143. Image[row1][0] = PORTA;
  144. Image[row1][0] = PORTA;
  145. Image[row1][0] = PORTA;
  146. Image[row1][0] = PORTA;
  147. Image[row1][0] = PORTA;
  148. Image[row1][0] = PORTA;
  149. Image[row1][0] = PORTA;
  150. Image[row1][0] = PORTA;
  151. Image[row1][0] = PORTA;
  152. Image[row1][0] = PORTA;
  153. Image[row1][0] = PORTA;
  154. Image[row1][0] = PORTA;
  155. Image[row1][0] = PORTA;
  156. Image[row1][0] = PORTA;
  157. Image[row1][0] = PORTA;
  158. Image[row1][0] = PORTA;
  159. Image[row1][0] = PORTA;
  160. Image[row1][0] = PORTA;
  161. Image[row1][0] = PORTA;
  162. Image[row1][0] = PORTA;
  163. Image[row1][0] = PORTA;
  164. Image[row1][0] = PORTA;
  165. Image[row1][0] = PORTA;
  166. Image[row1][0] = PORTA;
  167. Image[row1][0] = PORTA;
  168. Image[row1][0] = PORTA;
  169. Image[row1][0] = PORTA;
  170. Image[row1][0] = PORTA;
  171. Image[row1][0] = PORTA;
  172. Image[row1][0] = PORTA;
  173. Image[row1][0] = PORTA;
  174. Image[row1][0] = PORTA;
  175. Image[row1][0] = PORTA;
  176. Image[row1][0] = PORTA;
  177. Image[row1][0] = PORTA;
  178. Image[row1][0] = PORTA;
  179. Image[row1][0] = PORTA;
  180. Image[row1][0] = PORTA;
  181. Image[row1][0] = PORTA;
  182. Image[row1][0] = PORTA;
  183. Image[row1][0] = PORTA;
  184. Image[row1][0] = PORTA;
  185. Image[row1][0] = PORTA;
  186. Image[row1][0] = PORTA;
  187. Image[row1][0] = PORTA;
  188. Image[row1][0] = PORTA;
  189. Image[row1][0] = PORTA;
  190. Image[row1][0] = PORTA;
  191. Image[row1][0] = PORTA;
  192. Image[row1][0] = PORTA;
  193. Image[row1][0] = PORTA;
  194. Image[row1][0] = PORTA;
  195. Image[row1][0] = PORTA;
  196. Image[row1][0] = PORTA;
  197. Image[row1][0] = PORTA;
  198. Image[row1][0] = PORTA;
  199. Image[row1][0] = PORTA;
  200. Image[row1][0] = PORTA;
  201. Image[row1][0] = PORTA;
  202. Image[row1][0] = PORTA;
  203. Image[row1][0] = PORTA;
  204. Image[row1][0] = PORTA;
  205. Image[row1][0] = PORTA;
  206. Image[row1][0] = PORTA;
  207. Image[row1][0] = PORTA;
  208. Image[row1][0] = PORTA;
  209. Image[row1][0] = PORTA;
  210. Image[row1][0] = PORTA;
  211. Image[row1][1] = PORTA;
  212. Image[row1][1] = PORTA;
  213. Image[row1][2] = PORTA;
  214. Image[row1][2] = PORTA;
  215. Image[row1][3] = PORTA;
  216. Image[row1][3] = PORTA;
  217. Image[row1][4] = PORTA;
  218. Image[row1][4] = PORTA;
  219. Image[row1][5] = PORTA;
  220. Image[row1][5] = PORTA;
  221. Image[row1][6] = PORTA;
  222. Image[row1][6] = PORTA;
  223. Image[row1][7] = PORTA;
  224. Image[row1][7] = PORTA;
  225. Image[row1][8] = PORTA;
  226. Image[row1][8] = PORTA;
  227. Image[row1][9] = PORTA;
  228. Image[row1][9] = PORTA;
  229. Image[row1][10] = PORTA;
  230. Image[row1][10] = PORTA;
  231. Image[row1][11] = PORTA;
  232. Image[row1][11] = PORTA;
  233. Image[row1][12] = PORTA;
  234. Image[row1][12] = PORTA;
  235. Image[row1][13] = PORTA;
  236. Image[row1][13] = PORTA;
  237. Image[row1][14] = PORTA;
  238. Image[row1][14] = PORTA;
  239. Image[row1][15] = PORTA;
  240. Image[row1][15] = PORTA;
  241. Image[row1][16] = PORTA;
  242. Image[row1][16] = PORTA;
  243. Image[row1][17] = PORTA;
  244. Image[row1][17] = PORTA;
  245. Image[row1][18] = PORTA;
  246. Image[row1][18] = PORTA;
  247. Image[row1][19] = PORTA;
  248. Image[row1][19] = PORTA;
  249. Image[row1][20] = PORTA;
  250. Image[row1][20] = PORTA;
  251. Image[row1][21] = PORTA;
  252. Image[row1][21] = PORTA;
  253. Image[row1][22] = PORTA;
  254. Image[row1][22] = PORTA;
  255. Image[row1][23] = PORTA;
  256. Image[row1][23] = PORTA;
  257. Image[row1][24] = PORTA;
  258. Image[row1][24] = PORTA;
  259. Image[row1][25] = PORTA;
  260. Image[row1][25] = PORTA;
  261. Image[row1][26] = PORTA;
  262. Image[row1][26] = PORTA;
  263. Image[row1][27] = PORTA;
  264. Image[row1][27] = PORTA;
  265. Image[row1][28] = PORTA;
  266. Image[row1][28] = PORTA;
  267. Image[row1][29] = PORTA;
  268. Image[row1][29] = PORTA;
  269. Image[row1][30] = PORTA;
  270. Image[row1][30] = PORTA;
  271. Image[row1][31] = PORTA;
  272. Image[row1][31] = PORTA;
  273. Image[row1][32] = PORTA;
  274. Image[row1][32] = PORTA;
  275. Image[row1][33] = PORTA;
  276. Image[row1][33] = PORTA;
  277. Image[row1][34] = PORTA;
  278. Image[row1][34] = PORTA;
  279. Image[row1][35] = PORTA;
  280. Image[row1][35] = PORTA;
  281. Image[row1][36] = PORTA;
  282. Image[row1][36] = PORTA;
  283. Image[row1][37] = PORTA;
  284. Image[row1][37] = PORTA;
  285. Image[row1][38] = PORTA;
  286. Image[row1][38] = PORTA;
  287. Image[row1][39] = PORTA;
  288. Image[row1][39] = PORTA;
  289. Image[row1][40] = PORTA;
  290. Image[row1][40] = PORTA;
  291. Image[row1][41] = PORTA;
  292. Image[row1][41] = PORTA;
  293. Image[row1][42] = PORTA;
  294. Image[row1][42] = PORTA;
  295. Image[row1][43] = PORTA;
  296. Image[row1][43] = PORTA;
  297. Image[row1][44] = PORTA;
  298. Image[row1][44] = PORTA;
  299. Image[row1][45] = PORTA;
  300. Image[row1][45] = PORTA;
  301. Image[row1][46] = PORTA;
  302. Image[row1][46] = PORTA;
  303. Image[row1][47] = PORTA;
  304. Image[row1][47] = PORTA;
  305. Image[row1][48] = PORTA;
  306. Image[row1][48] = PORTA;
  307. Image[row1][49] = PORTA;
  308. Image[row1][49] = PORTA;
  309. Image[row1][50] = PORTA;
  310. Image[row1][50] = PORTA;
  311. Image[row1][51] = PORTA;
  312. Image[row1][51] = PORTA;
  313. Image[row1][52] = PORTA;
  314. Image[row1][52] = PORTA;
  315. Image[row1][53] = PORTA;
  316. Image[row1][53] = PORTA;
  317. Image[row1][54] = PORTA;
  318. Image[row1][54] = PORTA;
  319. Image[row1][55] = PORTA;
  320. Image[row1][55] = PORTA;
  321. Image[row1][56] = PORTA;
  322. Image[row1][56] = PORTA;
  323. Image[row1][57] = PORTA;
  324. Image[row1][57] = PORTA;
  325. Image[row1][58] = PORTA;
  326. Image[row1][58] = PORTA;
  327. Image[row1][59] = PORTA;
  328. Image[row1][59] = PORTA;
  329. Image[row1][60] = PORTA;
  330. Image[row1][60] = PORTA;
  331. Image[row1][61] = PORTA;
  332. Image[row1][61] = PORTA;
  333. Image[row1][62] = PORTA;
  334. Image[row1][62] = PORTA;
  335. Image[row1][63] = PORTA;
  336. Image[row1][63] = PORTA;
  337. Image[row1][64] = PORTA;
  338. Image[row1][64] = PORTA;
  339. Image[row1][65] = PORTA;
  340. Image[row1][65] = PORTA;
  341. Image[row1][66] = PORTA;
  342. Image[row1][66] = PORTA;
  343. Image[row1][67] = PORTA;
  344. Image[row1][67] = PORTA;
  345. Image[row1][68] = PORTA;
  346. Image[row1][68] = PORTA;
  347. Image[row1][69] = PORTA;
  348. Image[row1][69] = PORTA;
  349. Image[row1][70] = PORTA;
  350. Image[row1][70] = PORTA;
  351. Image[row1][71] = PORTA;
  352. Image[row1][71] = PORTA;
  353. Image[row1][72] = PORTA;
  354. Image[row1][72] = PORTA;
  355. Image[row1][73] = PORTA;
  356. Image[row1][73] = PORTA;
  357. Image[row1][74] = PORTA;
  358. Image[row1][74] = PORTA;
  359. row1++;
  360. if(row1==ROW_MAX)
  361. {
  362. TIE_C0I = 0;
  363. TIE_C1I = 0;
  364. sign=1;
  365. }
  366. }
  367. }
  368. #pragma CODE_SEG NON_BANKED
  369. void interrupt 20 SCI0_re(void)
  370. {
  371. if(SciRead()=='s')
  372. {
  373. SciTx(0x55);
  374. SciTx(0xAA);
  375. SciTxs("095075");
  376. if(sign==1){

  377. for(i=0;i<ROW_MAX;i++)
  378. for(j=7;j<LINE_MAX-7;j++){
  379. SciTx(Image[i][j]);
  380. if(j=LINE_MAX-7)
  381. SciTx('\n');

  382. }
  383. }

  384. }
  385. }
复制代码

4

主题

26

帖子

0

精华

高级会员

Rank: 4

积分
558
威望
402
贡献
66
兑换币
0
注册时间
2011-3-3
在线时间
45 小时
2#
 楼主| 发表于 2011-6-11 09:34:01 | 只看该作者
下面是通信协议上位机(PC机)
点击“采集图像”按钮后,将通过串口发送一个字符‘s’给下位机,表示采集图像开始。
下位机(单片机)
下位机通过串口收到采集图像命令后,先返回应答信号,应答信号为两个字节,分别为16进制的0x55,0xAA。
接着发送图像的宽度值W和高度值H,各占三个字节,比如宽度W为40,高度H为30,则发送字符串‘040030’。又如宽度W为320,高度H为240,则发送字符串‘320240’。
接下来按顺序发送W*H个图像像素点的灰度值,每个灰度值为一个字节(数值大小范围0-255)。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关于我们|联系我们|小黑屋|智能车制作 ( 黑ICP备2022002344号

GMT+8, 2024-12-29 21:30 , Processed in 0.047279 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表