Thank you for visiting my blog!
This blog is under maintenance and updates.
We will come back soon! 😄
Thank you for visiting my blog!
This blog is under maintenance and updates.
We will come back soon! 😄
Étapes du processus de reconnaissance de visage. |
Eye detection using MATLAB |
faceDetector = vision.CascadeObjectDetector('C:\Users\Imed\Desktop\Projet_sign_detection_matlab\eye.xml');
pointTracker = vision.PointTracker('MaxBidirectionalError', 8);
cam = webcam();
videoFrame = snapshot(cam);
frameSize = size(videoFrame);
videoPlayer = vision.VideoPlayer('Position', [100 100 [frameSize(2), frameSize(1)]+30]);
runLoop = true;
numPts = 0;
frameCount = 0;
while runLoop && frameCount < 800
videoFrame = snapshot(cam);
videoFrameGray = rgb2gray(videoFrame);
frameCount = frameCount + 1;
if numPts < 10
bbox = faceDetector.step(videoFrameGray);
if ~isempty(bbox)
% Find corner points inside the detected region.
points = detectMinEigenFeatures(videoFrameGray, 'ROI', bbox(1, :));
% Re-initialize the point tracker.
xyPoints = points.Location;
numPts = size(xyPoints,1);
release(pointTracker);
initialize(pointTracker, xyPoints, videoFrameGray);
% Save a copy of the points.
oldPoints = xyPoints;
bboxPoints = bbox2points(bbox(1, :));
% Convert the box corners into the [x1 y1 x2 y2 x3 y3 x4 y4]
% format required by insertShape.
bboxPolygon = reshape(bboxPoints', 1, []);
% Display a bounding box around the detected face.
videoFrame = insertShape(videoFrame, 'Polygon', bboxPolygon, 'LineWidth', 3);
% Display detected corners.
videoFrame = insertMarker(videoFrame, xyPoints, '+', 'Color', 'white');
end
else
% Tracking mode.
[xyPoints, isFound] = step(pointTracker, videoFrameGray);
visiblePoints = xyPoints(isFound, :);
oldInliers = oldPoints(isFound, :);
numPts = size(visiblePoints, 1);
if numPts >= 10
% Estimate the geometric transformation between the old points
% and the new points.
[xform, oldInliers, visiblePoints] = estimateGeometricTransform(...
oldInliers, visiblePoints, 'similarity', 'MaxDistance', 4);
% Apply the transformation to the bounding box.
bboxPoints = transformPointsForward(xform, bboxPoints);
% Convert the box corners into the [x1 y1 x2 y2 x3 y3 x4 y4]
% format required by insertShape.
bboxPolygon = reshape(bboxPoints', 1, []);
% Display a bounding box around the face being tracked.
videoFrame = insertShape(videoFrame, 'Polygon', bboxPolygon, 'LineWidth', 3);
position = [1 50; 100 50];
value = [111 pi];text_str = 'eye';position =xyPoints;
box_color = {'red'};
hh=[bboxPoints(4,1) bboxPoints(4,2)];
videoFrame= insertText(videoFrame,hh,text_str,'FontSize',14,'BoxColor',...
box_color,'BoxOpacity',0.6,'TextColor','white');
% Display tracked points.
videoFrame = insertMarker(videoFrame, visiblePoints, '+', 'Color', 'white');
% Reset the points.
oldPoints = visiblePoints;
setPoints(pointTracker, oldPoints);
end
end
% Display the annotated video frame using the video player object.
step(videoPlayer, videoFrame);
% Check whether the video player window has been closed.
runLoop = isOpen(videoPlayer);
end
% Clean up.
clear cam;
release(videoPlayer);
release(pointTracker);
release(faceDetector);
//LCD Module Connections
#define LCD_RS_PIN PIN_D1
#define LCD_RW_PIN PIN_D2
#define LCD_ENABLE_PIN PIN_D3
#define LCD_DATA4 PIN_D4
#define LCD_DATA5 PIN_D5
#define LCD_DATA6 PIN_D6
#define LCD_DATA7 PIN_D7
//End LCD Module Connections
//#define USE_RW_PIN 0 // donc't use RW PIN // These are the line addresses for most 4x20 LCDs. #define LCD_LINE_1_ADDRESS 0x00 #define LCD_LINE_2_ADDRESS 0x40 #define LCD_LINE_3_ADDRESS 0x14 #define LCD_LINE_4_ADDRESS 0x54 #define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines(or more) int8 lcd_line; int8 const LCD_INIT_STRING[4] = { 0x20 | (lcd_type << 2), // Set mode: 4-bit, 2+ lines, 5x8 dots 0xc, // Display on 1, // Clear display 6 // Increment cursor }; //------------------------------------- void lcd_send_nibble(int8 nibble) { // Note: !! converts an integer expression // to a boolean (1 or 0). output_bit(LCD_DB4, !!(nibble & 1)); output_bit(LCD_DB5, !!(nibble & 2)); output_bit(LCD_DB6, !!(nibble & 4)); output_bit(LCD_DB7, !!(nibble & 8)); delay_cycles(1); output_high(LCD_E); delay_us(2); output_low(LCD_E); } #ifdef USE_RW_PIN int8 lcd_read_nibble(void) { int8 retval; // Create bit variables so that we can easily set // individual bits in the retval variable. #bit retval_0 = retval.0 #bit retval_1 = retval.1 #bit retval_2 = retval.2 #bit retval_3 = retval.3 retval = 0; output_high(LCD_E); delay_us(1); retval_0 = input(LCD_DB4); retval_1 = input(LCD_DB5); retval_2 = input(LCD_DB6); retval_3 = input(LCD_DB7); output_low(LCD_E); delay_us(1); return(retval); } #endif //--------------------------------------- // Read a byte from the LCD and return it. #ifdef USE_RW_PIN int8 lcd_read_byte(void) { int8 low; int8 high; output_high(LCD_RW); delay_cycles(1); high = lcd_read_nibble(); low = lcd_read_nibble(); return( (high<<4) | low); } #endif //---------------------------------------- // Send a byte to the LCD. void lcd_send_byte(int8 address, int8 n) { output_low(LCD_RS); #ifdef USE_RW_PIN while(bit_test(lcd_read_byte(),7)) ; #else delay_us(60); #endif if(address) output_high(LCD_RS); else output_low(LCD_RS); delay_cycles(1); #ifdef USE_RW_PIN output_low(LCD_RW); delay_cycles(1); #endif output_low(LCD_E); lcd_send_nibble(n >> 4); lcd_send_nibble(n & 0xf); } //---------------------------- void lcd_init(void) { int8 i; lcd_line = 1; output_low(LCD_RS); #ifdef USE_RW_PIN output_low(LCD_RW); #endif output_low(LCD_E); // Some LCDs require 15 ms minimum delay after // power-up. Others require 30 ms. I'm going // to set it to 35 ms, so it should work with // all of them. delay_ms(35); for(i=0 ;i < 3; i++) { lcd_send_nibble(0x03); delay_ms(5); } lcd_send_nibble(0x02); for(i=0; i < sizeof(LCD_INIT_STRING); i++) { lcd_send_byte(0, LCD_INIT_STRING[i]); // If the R/W signal is not used, then // the busy bit can't be polled. One of // the init commands takes longer than // the hard-coded delay of 50 us, so in // that case, lets just do a 5 ms delay // after all four of them. #ifndef USE_RW_PIN delay_ms(5); #endif } } //---------------------------- void lcd_gotoxy(int8 x, int8 y) { int8 address; switch(y) { case 1: address = LCD_LINE_1_ADDRESS; break; case 2: address = LCD_LINE_2_ADDRESS; break; case 3: address = LCD_LINE_3_ADDRESS; break; case 4: address = LCD_LINE_4_ADDRESS; break; default: address = LCD_LINE_1_ADDRESS; break; } address += x-1; lcd_send_byte(0, 0x80 | address); } //----------------------------- void lcd_putc(char c) { switch(c) { case '\f': lcd_send_byte(0,1); lcd_line = 1; delay_ms(2); break; case '\n': lcd_gotoxy(1, ++lcd_line); break; case '\b': lcd_send_byte(0,0x10); break; default: lcd_send_byte(1,c); break; } } //------------------------------ #ifdef USE_RW_PIN char lcd_getc(int8 x, int8 y) { char value; lcd_gotoxy(x,y); // Wait until busy flag is low. while(bit_test(lcd_read_byte(),7)); output_high(LCD_RS); value = lcd_read_byte(); output_low(LCD_RS); return(value); } #endif
Phénomène d'agitation thermique |
Calculatrice du bruit thermique |
Montage du capteur LM35 pour mesurer une température négative |
#include <16F877.h>
#device adc=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES RESERVED //Used to set the reserved FUSE bits
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7, timeout=2000)
#include <math.h>
#define LCD_ENABLE_PIN PIN_B0 ////
#define LCD_RS_PIN PIN_B1 ////
#define LCD_RW_PIN PIN_B2 ////
#define LCD_DATA4 PIN_B4 ////
#define LCD_DATA5 PIN_B5 ////
#define LCD_DATA6 PIN_B6 ////
#define LCD_DATA7 PIN_B7
#define LCD_TYPE 2
#include "LCD420.C"
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
void main()
{
lcd_init();
setup_adc_ports(AN0_an1_an3);
setup_adc(ADC_CLOCK_DIV_8);
delay_us(20);
while(1){
set_adc_channel(0); // calculer tension1
delay_ms (10);
int16 tension1 = read_adc();
set_adc_channel(1); // calculer tension2
delay_ms (10);
int16 tension2 = read_adc();
signed int16 temperature = tension1 - tension2; // mesurer la difference
lcd_gotoxy(1,1);
printf(lcd_putc,"temp= %2.1f",temperature*5.*100./1023.); // afficher la temperature
lcd_putc(223); //afficher la signe du C
printf(lcd_putc,"C ");
}}//end void main()
|
Simulation du circuit : PIC 16F877 + LCD + LM35 (température positive) |
VCC | 5V / 3V3 |
GND | 0V |
SCL | Pin SCL I2C |
SDA | Pin SDA dans l'interface I2C |
XDA | Broches de données (se connecter avec d'autres capteurs) |
XCL | Impulsion d'horloge (connecté à d'autres capteurs) |
AD0 | Bit0 de l'adresse I2C |
INT | Initialiser |
1
2
3
4
5
6
7
8
|
void Mpu6050_Write(unsigned char address,unsigned char Data)
{
MPU6050_I2C_Start();
MPU6050_I2C_Wr( MPU6050_ADDRESS );
MPU6050_I2C_Wr( address);
MPU6050_I2C_Wr( Data);
MPU6050_I2C_Stop();
}
|
1
2
3
4
5
6
7
8
9
10
11
12
|
unsigned char MPU6050_Read(unsigned char address)
{
int8 Data;
MPU6050_I2C_Start();
MPU6050_I2C_Wr( MPU6050_ADDRESS );
MPU6050_I2C_Wr(address);
MPU6050_I2C_Start();
MPU6050_I2C_Wr( MPU6050_ADDRESS | 1 );
Data=MPU6050_I2C_Rd(0);
MPU6050_I2C_Stop();
return Data;
}
|
Tableau I2C pour MPU6050 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
#include <ex_usb_common.h>
#define MPU_SDA PIN_E0
#define MPU_SCL PIN_E1
#use I2C(master, sda=MPU_SDA, scl=MPU_SCL)
#use TIMER(TIMER=1, TICK=1ms, BITS=16, NOISR)
#define RAD_TO_DEG 180/PI
#define LCD_ENABLE_PIN PIN_D2
#define LCD_RS_PIN PIN_D0
#define LCD_RW_PIN PIN_D1
#define LCD_DATA4 PIN_D4
#define LCD_DATA5 PIN_D5
#define LCD_DATA6 PIN_D6
#define LCD_DATA7 PIN_D7
#include <lcd.c>
/////////////////////////////////////////////////////////////////////////////
//
// Include the CCS USB Libraries. See the comments at the top of these
// files for more information
//
/////////////////////////////////////////////////////////////////////////////
#if __USB_PIC_PERIF__
#if defined(__PCM__)
#include <pic16f_usb.h> //Microchip PIC16Fxxxx hardware layer for usb.c
#elif defined(__PCH__)
#include <pic18_usb.h> //Microchip PIC18Fxx5x hardware layer for usb.c
#elif defined(__PCD__)
#include <pic24_usb.h> //Microchip PIC18Fxx5x hardware layer for usb.c
#endif
#else
#include <usbn960x.h> //National 960x hardware layer for usb.c
#endif
#include <usb_desc_keyboard.h> //USB Configuration and Device descriptors for this UBS device
#include <usb.c> //handles usb setup tokens and get descriptor reports
#include "MPU6050.c"
#include "math.h"
#include "Kalman.h"
typedef enum
{
KB_MODIFIER_LEFT_CTRL = 1,
KB_MODIFIER_LEFT_SHIFT = 2,
KB_MODIFIER_LEFT_ALT = 4,
KB_MODIFIER_LEFT_GUI = 8,
KB_MODIFIER_RIGHT_CTRL = 16,
KB_MODIFIER_RIGHT_SHIFT = 32,
KB_MODIFIER_RIGHT_ALT = 64,
KB_MODIFIER_RIGHT_GUI = 128
} kb_modifier_t;
typedef enum
{
USB_KBD_SCANCODE_ESC = 0x29,
USB_KBD_SCANCODE_CAPS_LOC = 0x39,
USB_KBD_SCANCODE_F1 = 0x3A, //F2 is 0x3B, F3 is 0x3C, etc. this is valid up to F12
USB_KBD_SCANCODE_PRTSC = 0x46,
USB_KBD_SCANCODE_SCROLL_LOCK = 0x47,
USB_KBD_SCANCODE_PAUSE = 0x48,
USB_KBD_SCANCODE_INS = 0x49,
USB_KBD_SCANCODE_HOME = 0x4A,
USB_KBD_SCANCODE_PG_UP = 0x4B,
USB_KBD_SCANCODE_DEL = 0x4C,
USB_KBD_SCANCODE_END = 0x4D,
USB_KBD_SCANCODE_PG_DN = 0x4E,
USB_KBD_SCANCODE_RIGHT = 0x4F,
USB_KBD_SCANCODE_LEFT = 0x50,
USB_KBD_SCANCODE_DOWN = 0x51,
USB_KBD_SCANCODE_UP = 0x52,
USB_KBD_SCANCODE_NUM_LOCK = 0x53,
USB_KBD_SCANCODE_WIN_MENU = 0x65,
USB_KBD_SCANCODE_F13 = 0x68, //F14 is 0x69, F15 is 0x6A, etc. this is valid up to F24
USB_KBD_SCANCODE_HELP = 0x75,
USB_KBD_SCANCODE_UNDO = 0x7A,
USB_KBD_SCANCODE_CUT = 0x7B,
USB_KBD_SCANCODE_COPY = 0x7C,
USB_KBD_SCANCODE_PASTE = 0x7D,
USB_KBD_SCANCODE_MUTE = 0x7F,
USB_KBD_SCANCODE_VOL_UP = 0x80,
USB_KBD_SCANCODE_VOL_DOWN = 0x81
} kb_scancode_t;
signed int16 accX,accY, accZ;
SIGNED int16 gyroX,gyroY,gyroZ;
DOUBLE accXangle,accYangle;
DOUBLE gyroXangle,gyroYangle;
DOUBLE kalAngleX,kalAngleY;
UNSIGNED int16 timer;
UNSIGNED int16 key=0x00,key2=0x00;
unsigned int16 mpu_6050_task(void)
{
//chuong trinh
accX = Mpu6050_GetData(MPU6050_RA_ACCEL_XOUT_H);
accY = Mpu6050_GetData(MPU6050_RA_ACCEL_YOUT_H);
accZ = Mpu6050_GetData(MPU6050_RA_ACCEL_ZOUT_H);
gyroX = Mpu6050_GetData(MPU6050_RA_GYRO_XOUT_H);
gyroY = Mpu6050_GetData(MPU6050_RA_GYRO_YOUT_H);
gyroZ = Mpu6050_GetData(MPU6050_RA_GYRO_ZOUT_H);
set_ticks(0);
accXangle = (atan2 (accY, accZ) + PI) * RAD_TO_DEG;
DOUBLE gyroXrate = (double) gyroX / 131.0;
gyroXangle += gyroXrate * ( (DOUBLE) (get_ticks () - timer) / 1000);
kalAngleX = kalmanCalculate (accXangle, gyroXrate, (get_ticks()-timer));
timer = get_ticks ();
set_ticks(0);
accYangle = (atan2 (accX, accZ) + PI) * RAD_TO_DEG;
DOUBLE gyroYrate = (double) gyroY / 131.0;
gyroYangle += gyroYrate * ( (DOUBLE) (get_ticks () - timer) / 1000);
kalAngleY = kalmanCalculate (accYangle, gyroYrate, (get_ticks()-timer));
timer = get_ticks ();
LCD_Gotoxy (1, 1) ;
printf (LCD_PUTC, "X=%f", kalAngleX);
key=0x00;
LCD_Gotoxy (10, 1) ;
printf (LCD_PUTC, " " );
if(kalAngleX>200)
{
LCD_Gotoxy (10, 1) ;
printf (LCD_PUTC, "back " );
key= 0x51;//Down
}
if((150<kalAngleX)&&(kalAngleX<170))
{
LCD_Gotoxy (10, 1) ;
printf (LCD_PUTC, "forward" );
key= 0x52;//Up
}
if(kalAngleX<150)
{
LCD_Gotoxy (10, 1) ;
printf (LCD_PUTC, "nitro " );
key= 0x2C;//Space
}
LCD_Gotoxy (1, 2) ;
printf (LCD_PUTC, "Y=%f", kalAngleY);
LCD_Gotoxy (10, 2) ;
printf (LCD_PUTC, " " );
key2=0x00;
if(kalAngleY>200)
{
LCD_Gotoxy (10, 2) ;
printf (LCD_PUTC, "left " );
key2= 0x50;
}
if(kalAngleY<160)
{
LCD_Gotoxy (10, 2) ;
printf (LCD_PUTC, "right " );
key2 = 0x4F;
}
delay_ms(50); //Khong co la se treo
return key;
}
//Het chuong trinh
void usb_debug_task(void)
{
static int8 last_connected;
static int8 last_enumerated;
int8 new_connected;
int8 new_enumerated;
new_connected=usb_attached();
new_enumerated=usb_enumerated();
if (new_connected)
LED_ON(LED2);
else
LED_OFF(LED2);
if (new_enumerated)
{
LED_ON(LED1);
LED_ON(LED2);
}
else
{
LED_OFF(LED1);
LED_OFF(LED2);
}
/*
if (new_connected && !last_connected)
printf (LCD_PUTC, "\fUSB connected\nwaiting for enumaration...");
if (!new_connected && last_connected)
printf (LCD_PUTC, "\fUSB disconnected\nwaiting for connection...");
if (new_enumerated && !last_enumerated)
printf (LCD_PUTC, "\fUSB enumerated\nby PC/HOST");
if (!new_enumerated && last_enumerated)
printf (LCD_PUTC, "\fUSB unenumerated by PC/HOST\nwaiting for enumeration...");
*/
last_connected=new_connected;
last_enumerated=new_enumerated;
}
/////////////////////////////////////////////////////////////////////////////
//
// usb_keyboard_task()
//
// Sends a packet of keyboard data. The protocol was specified in the HID
// report descriptor (see usb_desc_kbmouse.h), and is:
// tx_msg[0] = modifier (see kb_modifier_t)
// tx_msg[1] = const 0
// tx_msg[2:6] = an array of held down keys. a=4, b=5, etc.
// if msg[2:7]={0} then no keys are held down
//
// rx_msg[0] = 5bit bitmap of led status
//
/////////////////////////////////////////////////////////////////////////////
void usb_keyboard_task(void)
{
unsigned int8 tx_msg[7];
unsigned int8 leds;
unsigned int16 scancode;
if (usb_tbe(1))
{
memset(tx_msg, 0x00, sizeof(tx_msg));
//scancode =mpu_6050_task();
//if(scancode!=0x00)
mpu_6050_task();
if(key!=0x00)
{
tx_msg[2] =key;//scancode;
}
if(key2!=0x00)
{
tx_msg[3] =key2;//scancode;
}
usb_put_packet(1, tx_msg, sizeof(tx_msg), USB_DTS_TOGGLE);
}
//receive NUM LOCK, CAPS LOCK, etc LED status from PC.
//we won't do anything with it.
if (usb_kbhit(1))
{
usb_get_packet(1, &leds, 1);
}
}
void main(void)
{
lcd_init ();
printf (LCD_PUTC, "\f MuaLinhKien.Vn \nPIC 16/18 Basic Kit");
delay_ms(1000);
HW_INIT();
LED_ON(LED1);
LED_OFF(LED2);
LED_OFF(LED3);
Mpu6050_Init () ;
delay_ms (500) ;
INT8 x;
x = Mpu6050_Read(MPU6050_RA_WHO_AM_I);
IF (x != 0x68)
{
LCD_Gotoxy (2, 0) ;
printf (LCD_PUTC, "Connection ERR!!!");
return;
}
usb_init_cs();
printf (LCD_PUTC, "\f");
while (TRUE)
{
usb_task();
usb_debug_task();
if (usb_enumerated())
{
usb_keyboard_task();
}
}
}
|
Introduction: Did you ever posed the question: How large software in industrial scale systems are designed ? Here I'll explai...