File size: 24,073 Bytes
4af2345 | 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 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Children's Drawing Emotion Analyzer</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
border-radius: 20px;
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
overflow: hidden;
}
.header {
background: linear-gradient(45deg, #4CAF50, #45a049);
color: white;
padding: 30px;
text-align: center;
}
.header h1 {
font-size: 2.5em;
margin-bottom: 10px;
}
.header p {
font-size: 1.2em;
opacity: 0.9;
}
.main-content {
padding: 40px;
}
.upload-section {
border: 3px dashed #ddd;
border-radius: 15px;
padding: 40px;
text-align: center;
margin-bottom: 30px;
transition: all 0.3s ease;
}
.upload-section:hover {
border-color: #4CAF50;
background-color: #f9f9f9;
}
.upload-section.dragover {
border-color: #4CAF50;
background-color: #e8f5e8;
}
#fileInput {
display: none;
}
.upload-btn {
background: linear-gradient(45deg, #4CAF50, #45a049);
color: white;
padding: 15px 30px;
border: none;
border-radius: 25px;
font-size: 1.1em;
cursor: pointer;
transition: transform 0.3s ease;
}
.upload-btn:hover {
transform: translateY(-2px);
}
.canvas-container {
display: flex;
gap: 20px;
margin: 30px 0;
flex-wrap: wrap;
}
.canvas-wrapper {
flex: 1;
min-width: 300px;
}
.canvas-wrapper h3 {
margin-bottom: 10px;
color: #333;
}
canvas {
border: 2px solid #ddd;
border-radius: 10px;
max-width: 100%;
height: auto;
}
.analysis-section {
margin-top: 30px;
padding: 25px;
background: #f8f9fa;
border-radius: 15px;
}
.color-stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin: 20px 0;
}
.color-card {
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
text-align: center;
}
.color-bar {
height: 10px;
border-radius: 5px;
margin: 10px 0;
}
.red-bar { background: #ff4757; }
.green-bar { background: #2ed573; }
.blue-bar { background: #3742fa; }
.emotion-result {
background: white;
padding: 25px;
border-radius: 15px;
margin-top: 20px;
border-left: 5px solid #4CAF50;
}
.emotion-indicators {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 15px;
margin-top: 20px;
}
.emotion-card {
padding: 15px;
border-radius: 10px;
border-left: 4px solid;
}
.positive { border-color: #4CAF50; background: #e8f5e8; }
.warning { border-color: #ff9800; background: #fff3e0; }
.alert { border-color: #f44336; background: #ffebee; }
.loading {
display: none;
text-align: center;
padding: 20px;
}
.spinner {
border: 4px solid #f3f3f3;
border-top: 4px solid #4CAF50;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin: 0 auto 10px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.info-box {
background: #e3f2fd;
border: 1px solid #2196f3;
border-radius: 10px;
padding: 20px;
margin-bottom: 20px;
}
.info-box h3 {
color: #1565c0;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🎨 Children's Drawing Emotion Analyzer</h1>
<p>Early Detection Tool for Emotional Well-being in Children</p>
</div>
<div class="main-content">
<div class="info-box">
<h3>How it works:</h3>
<p>Upload a drawing image, and our algorithm will analyze the color usage to provide insights into the child's emotional state. This tool is designed to assist educators and counselors in early detection of emotional patterns.</p>
</div>
<div class="upload-section" id="uploadSection">
<h2>📁 Upload Drawing Image</h2>
<p>Drag and drop an image here or click to select</p>
<br>
<button class="upload-btn" onclick="document.getElementById('fileInput').click()">
Choose Image
</button>
<input type="file" id="fileInput" accept="image/*">
</div>
<div class="loading" id="loadingDiv">
<div class="spinner"></div>
<p>Analyzing drawing...</p>
</div>
<div class="canvas-container" id="canvasContainer" style="display: none;">
<div class="canvas-wrapper">
<h3>Original Image</h3>
<canvas id="originalCanvas"></canvas>
</div>
<div class="canvas-wrapper">
<h3>White Balance Corrected</h3>
<canvas id="correctedCanvas"></canvas>
</div>
</div>
<div class="analysis-section" id="analysisSection" style="display: none;">
<h2>🔍 Color Analysis Results</h2>
<div class="color-stats" id="colorStats">
<!-- Color statistics will be populated here -->
</div>
<div class="emotion-result" id="emotionResult">
<!-- Emotion analysis will be populated here -->
</div>
</div>
</div>
</div>
<script>
class DrawingAnalyzer {
constructor() {
this.setupEventListeners();
this.originalCanvas = document.getElementById('originalCanvas');
this.correctedCanvas = document.getElementById('correctedCanvas');
this.originalCtx = this.originalCanvas.getContext('2d');
this.correctedCtx = this.correctedCanvas.getContext('2d');
}
setupEventListeners() {
const fileInput = document.getElementById('fileInput');
const uploadSection = document.getElementById('uploadSection');
fileInput.addEventListener('change', (e) => this.handleImageUpload(e));
// Drag and drop functionality
uploadSection.addEventListener('dragover', (e) => {
e.preventDefault();
uploadSection.classList.add('dragover');
});
uploadSection.addEventListener('dragleave', () => {
uploadSection.classList.remove('dragover');
});
uploadSection.addEventListener('drop', (e) => {
e.preventDefault();
uploadSection.classList.remove('dragover');
const files = e.dataTransfer.files;
if (files.length > 0) {
this.processImage(files[0]);
}
});
}
handleImageUpload(event) {
const file = event.target.files[0];
if (file) {
this.processImage(file);
}
}
processImage(file) {
document.getElementById('loadingDiv').style.display = 'block';
document.getElementById('canvasContainer').style.display = 'none';
document.getElementById('analysisSection').style.display = 'none';
const reader = new FileReader();
reader.onload = (e) => {
const img = new Image();
img.onload = () => {
setTimeout(() => {
this.analyzeImage(img);
}, 500);
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
}
analyzeImage(img) {
// Set canvas dimensions
const maxWidth = 400;
const maxHeight = 300;
let width = img.width;
let height = img.height;
if (width > maxWidth) {
height = (height * maxWidth) / width;
width = maxWidth;
}
if (height > maxHeight) {
width = (width * maxHeight) / height;
height = maxHeight;
}
this.originalCanvas.width = width;
this.originalCanvas.height = height;
this.correctedCanvas.width = width;
this.correctedCanvas.height = height;
// Draw original image
this.originalCtx.drawImage(img, 0, 0, width, height);
// Get image data for processing
const imageData = this.originalCtx.getImageData(0, 0, width, height);
const correctedImageData = imageData;
// Draw corrected image
this.correctedCtx.putImageData(correctedImageData, 0, 0);
// Analyze colors
const colorAnalysis = this.analyzeColors(correctedImageData);
const emotionAnalysis = this.analyzeEmotions(colorAnalysis);
// Display results
this.displayResults(colorAnalysis, emotionAnalysis);
document.getElementById('loadingDiv').style.display = 'none';
document.getElementById('canvasContainer').style.display = 'flex';
document.getElementById('analysisSection').style.display = 'block';
}
whiteBalanceCorrection(imageData) {
const data = new Uint8ClampedArray(imageData.data);
let rSum = 0, gSum = 0, bSum = 0;
let pixelCount = 0;
// Calculate average RGB values
for (let i = 0; i < data.length; i += 4) {
const r = data[i];
const g = data[i + 1];
const b = data[i + 2];
// Skip very dark pixels (likely not white areas)
if (r + g + b > 150) {
rSum += r;
gSum += g;
bSum += b;
pixelCount++;
}
}
if (pixelCount === 0) return new ImageData(data, imageData.width, imageData.height);
const rAvg = rSum / pixelCount;
const gAvg = gSum / pixelCount;
const bAvg = bSum / pixelCount;
// Calculate correction factors
const grayTarget = 128;
const rFactor = grayTarget / rAvg || 1;
const gFactor = grayTarget / gAvg || 1;
const bFactor = grayTarget / bAvg || 1;
// Apply correction
for (let i = 0; i < data.length; i += 4) {
data[i] = Math.min(255, data[i] * rFactor);
data[i + 1] = Math.min(255, data[i + 1] * gFactor);
data[i + 2] = Math.min(255, data[i + 2] * bFactor);
}
return new ImageData(data, imageData.width, imageData.height);
}
analyzeColors(imageData) {
const data = imageData.data;
let totalPixels = 0;
let redTotal = 0, greenTotal = 0, blueTotal = 0;
let colorPixels = 0;
for (let i = 0; i < data.length; i += 4) {
const r = data[i];
const g = data[i + 1];
const b = data[i + 2];
const alpha = data[i + 3];
if (alpha > 128) { // Skip transparent pixels
totalPixels++;
// Skip white/near-white pixels (paper background)
if (r + g + b < 700) {
colorPixels++;
redTotal += r;
greenTotal += g;
blueTotal += b;
}
}
}
const redPercentage = colorPixels > 0 ? (redTotal / (colorPixels * 255)) * 100 : 0;
const greenPercentage = colorPixels > 0 ? (greenTotal / (colorPixels * 255)) * 100 : 0;
const bluePercentage = colorPixels > 0 ? (blueTotal / (colorPixels * 255)) * 100 : 0;
return {
red: Math.round(redPercentage * 10) / 10,
green: Math.round(greenPercentage * 10) / 10,
blue: Math.round(bluePercentage * 10) / 10,
totalColorPixels: colorPixels,
totalPixels: totalPixels
};
}
analyzeEmotions(colorAnalysis) {
const { red, green, blue } = colorAnalysis;
// Emotional indicators based on color psychology research
const indicators = [];
let anxietyScore = 0;
let overallMood = 'neutral';
// Red analysis (Energy, Anger, Excitement, Aggression)
if (red > 25) {
indicators.push({
type: 'warning',
emotion: 'High Energy/Potential Aggression',
description: `High red usage (${red}%) may indicate strong emotions, excitement, or potential aggression.`,
recommendation: 'Monitor for signs of frustration or overstimulation.'
});
anxietyScore += 1;
} else if (red > 15) {
indicators.push({
type: 'positive',
emotion: 'Healthy Energy',
description: `Moderate red usage (${red}%) suggests healthy energy and enthusiasm.`,
recommendation: 'Positive indicator of normal emotional expression.'
});
} else if (red < 5) {
indicators.push({
type: 'warning',
emotion: 'Low Energy',
description: `Very low red usage (${red}%) might indicate low energy or withdrawal.`,
recommendation: 'Consider encouraging more active engagement.'
});
anxietyScore += 0.5;
}
// Blue analysis (Calm, Sadness, Introversion, Peace)
if (blue > 30) {
indicators.push({
type: 'alert',
emotion: 'Possible Sadness/Withdrawal',
description: `Very high blue usage (${blue}%) may indicate sadness or excessive introversion.`,
recommendation: 'Consider gentle inquiry about emotional state.'
});
anxietyScore += 2;
} else if (blue > 20) {
indicators.push({
type: 'warning',
emotion: 'Reflective/Calm Nature',
description: `High blue usage (${blue}%) suggests a calm, reflective personality.`,
recommendation: 'Monitor for balance with other emotions.'
});
anxietyScore += 0.5;
} else if (blue > 10) {
indicators.push({
type: 'positive',
emotion: 'Balanced Calmness',
description: `Moderate blue usage (${blue}%) indicates healthy emotional balance.`,
recommendation: 'Good sign of emotional stability.'
});
}
// Green analysis (Growth, Harmony, Nature, Balance)
if (green > 25) {
indicators.push({
type: 'positive',
emotion: 'Harmony & Growth',
description: `High green usage (${green}%) indicates strong connection to nature and balanced emotions.`,
recommendation: 'Excellent sign of emotional health and growth mindset.'
});
anxietyScore -= 1; // Green reduces anxiety score
} else if (green > 15) {
indicators.push({
type: 'positive',
emotion: 'Natural Balance',
description: `Good green usage (${green}%) suggests emotional balance and stability.`,
recommendation: 'Positive indicator of healthy emotional development.'
});
} else if (green < 5) {
indicators.push({
type: 'warning',
emotion: 'Potential Imbalance',
description: `Very low green usage (${green}%) might indicate lack of emotional balance.`,
recommendation: 'Consider activities that promote harmony and balance.'
});
anxietyScore += 0.5;
}
// Overall anxiety assessment
let anxietyLevel = 'Low';
let anxietyDescription = 'The drawing shows healthy emotional expression with no significant anxiety indicators.';
if (anxietyScore >= 2.5) {
anxietyLevel = 'High';
anxietyDescription = 'Multiple indicators suggest possible anxiety or emotional distress. Professional consultation recommended.';
} else if (anxietyScore >= 1.5) {
anxietyLevel = 'Moderate';
anxietyDescription = 'Some indicators suggest mild anxiety or emotional sensitivity. Continue monitoring.';
} else if (anxietyScore >= 0.5) {
anxietyLevel = 'Mild';
anxietyDescription = 'Minor indicators present but generally within normal range.';
}
// Determine overall mood
if (green > red && green > blue) {
overallMood = 'Balanced and Harmonious';
} else if (red > blue && red > green) {
overallMood = 'Energetic and Active';
} else if (blue > red && blue > green) {
overallMood = 'Calm and Reflective';
} else {
overallMood = 'Mixed Emotions';
}
return {
indicators,
anxietyLevel,
anxietyDescription,
anxietyScore: Math.max(0, anxietyScore),
overallMood
};
}
displayResults(colorAnalysis, emotionAnalysis) {
// Display color statistics
const colorStatsDiv = document.getElementById('colorStats');
colorStatsDiv.innerHTML = `
<div class="color-card">
<h3 style="color: #ff4757;">Red Usage</h3>
<div class="color-bar red-bar" style="width: ${Math.min(colorAnalysis.red * 2, 100)}%;"></div>
<p><strong>${colorAnalysis.red}%</strong></p>
<small>Energy, Excitement, Aggression</small>
</div>
<div class="color-card">
<h3 style="color: #2ed573;">Green Usage</h3>
<div class="color-bar green-bar" style="width: ${Math.min(colorAnalysis.green * 2, 100)}%;"></div>
<p><strong>${colorAnalysis.green}%</strong></p>
<small>Harmony, Growth, Balance</small>
</div>
<div class="color-card">
<h3 style="color: #3742fa;">Blue Usage</h3>
<div class="color-bar blue-bar" style="width: ${Math.min(colorAnalysis.blue * 2, 100)}%;"></div>
<p><strong>${colorAnalysis.blue}%</strong></p>
<small>Calm, Reflection, Sadness</small>
</div>
`;
// Display emotion analysis
const emotionResultDiv = document.getElementById('emotionResult');
emotionResultDiv.innerHTML = `
<h3>🧠 Emotional Analysis Summary</h3>
<p><strong>Overall Mood:</strong> ${emotionAnalysis.overallMood}</p>
<p><strong>Anxiety Level:</strong> <span style="color: ${emotionAnalysis.anxietyLevel === 'High' ? '#f44336' : emotionAnalysis.anxietyLevel === 'Moderate' ? '#ff9800' : '#4CAF50'};">${emotionAnalysis.anxietyLevel}</span></p>
<p><strong>Assessment:</strong> ${emotionAnalysis.anxietyDescription}</p>
<div class="emotion-indicators">
${emotionAnalysis.indicators.map(indicator => `
<div class="emotion-card ${indicator.type}">
<h4>${indicator.emotion}</h4>
<p>${indicator.description}</p>
<small><strong>Recommendation:</strong> ${indicator.recommendation}</small>
</div>
`).join('')}
</div>
<div style="margin-top: 20px; padding: 15px; background: #fff3cd; border: 1px solid #ffeaa7; border-radius: 8px;">
<h4>⚠️ Important Note</h4>
<p>This analysis is a screening tool only and should not replace professional psychological assessment. Use results as a starting point for further observation and professional consultation when needed.</p>
</div>
`;
}
}
// Initialize the application
document.addEventListener('DOMContentLoaded', () => {
new DrawingAnalyzer();
});
</script>
</body>
</html> |