Hiện mình đang học lập trình trên nios 2, có 1 cái code mà mình ko hiểu.
Mong mọi người giúp đỡ, chỉ giùm mình.
Hiện code phục vụ việc xử lí ảnh trên board DE2
Mình cảm ơn!
Mong mọi người giúp đỡ, chỉ giùm mình.
Hiện code phục vụ việc xử lí ảnh trên board DE2
Mình cảm ơn!
Code:
*******************************************************************************/ #include <io.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include "system.h" #include "sys/alt_timestamp.h" #include "sys/alt_irq.h" #include "pio.h" #include "altera_avalon_dma.h" #include "altera_avalon_dma_regs.h" #define SIZE_V 240 // giá trị pixel của anh là 240*320 #define SIZE_H 320 #define KIRSCH 1 #define PREWITT 2 #define SOBEL 3 #define hpf_1 1 #define hpf_2 2 #define hpf_3 3 #define lpf_6 1 #define lpf_9 2 #define lpf_10 3 #define lpf_16 4 #define lpf_32 5 #define g7 7 #define g9 9 #define THRESHOLD_K 200 //nguong cho bo loc kirsch #define THRESHOLD_P 130 //nguong cho bo loc prewitt #define THRESHOLD_S 200 //nguong cho bo loc sobel #define THRESHOLD_Q 30 //nguong cho bo loc nhanh #define SWITCH 0x01101060 #define GREEN_LED 0x01101080 #define RED_LED 0x01101070 #define SRAM1 0x01080000 #define SRAM2 0x01092C00 /******************************************************************************* * VGA: 26 bit : 9->0 so dong, 25->16 so pix tren dong * 640_0_480 : 0x028001E0 * 320_0_240 : 0x14000F0 *******************************************************************************/ //#define VGA_PIX_SIZE 0x028001E0 #define VGA_PIX_SIZE 0x14000F0 #define VGA_CONFIG_BASE 0x01101040 #define fileanh "/mnt/host/result.raw" int main() { unsigned long choice,kt; unsigned char* input_image; unsigned char* output_image; FILE *fp; input_image = (unsigned char*) SRAM1; output_image = (unsigned char*) SRAM2; //clear image clear(input_image); clear(output_image); IOWR(VGA_CONFIG_BASE, 1, VGA_PIX_SIZE); // configure the VGA controller IOWR(VGA_CONFIG_BASE, 2, 0x0003); // turn on the VGA controller with interrupts disabled. IOWR(VGA_CONFIG_BASE, 0, SRAM1 ); a01(input_image); //read image choice = 0; kt = choice; while(1) { choice = IORD(SWITCH,0); IOWR(GREEN_LED,0,0); IOWR(RED_LED,0,0); if(kt != choice) { usleep(3000000); choice = IORD(SWITCH,0); kt = choice; if((choice & 0x20000) == 0x20000) { printf("\nBan da thoat khoi chuong trinh !"); IOWR(GREEN_LED,0,0xff); IOWR(RED_LED,0,0x3ffff); return 0; } if((choice & 0x10000) == 0x10000) { printf("\n\nDang luu anh vao tap tin !"); fp = fopen (fileanh,"wb"); if (fp == NULL) { printf ("\nKhong tim thay file anh xuat ! "); return 0; } IOWR(GREEN_LED,0,0xff); fwrite (output_image, 1, SIZE_V*SIZE_H, fp); fclose (fp); printf("\nLuu thanh cong !"); } else { switch(choice & 0xff) { case 0x01: printf("\n\nBan da chon bo loc thong thap ti so 1/6"); printf("\nDang thuc hien .... vui long cho trong giay lat !"); IOWR(GREEN_LED,0,0xff); low_pass_filter(input_image,output_image,lpf_6); printf("\nHoan tat !"); break; case 0x02: printf("\n\nBan da chon bo loc thong thap ti so 1/9"); printf("\nDang thuc hien .... vui long cho trong giay lat !"); IOWR(GREEN_LED,0,0xff); low_pass_filter(input_image,output_image,lpf_9); printf("\nHoan tat !"); break; case 0x03: printf("\n\nBan da chon bo loc thong thap ti so 1/10"); printf("\nDang thuc hien .... vui long cho trong giay lat !"); IOWR(GREEN_LED,0,0xff); low_pass_filter(input_image,output_image,lpf_10); printf("\nHoan tat !"); break; default: printf("\n\nXin chon dung che do !"); IOWR(RED_LED,0,0x3ffff); break; } } } } return 0; }
Comment