sca.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>视频对象检测</title>
  7. <link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
  8. <!-- 使用更可靠的 Vue 2 CDN -->
  9. <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.14/vue.js"></script>
  10. <style>
  11. @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');
  12. body {
  13. font-family: 'Inter', sans-serif;
  14. background-color: #f3f4f6;
  15. }
  16. .upload-area {
  17. border: 2px dashed #e5e7eb;
  18. transition: all 0.3s ease;
  19. background: rgba(255, 255, 255, 0.8);
  20. backdrop-filter: blur(10px);
  21. }
  22. .upload-area:hover {
  23. border-color: #6366f1;
  24. background: rgba(255, 255, 255, 0.9);
  25. transform: translateY(-2px);
  26. }
  27. .analyzing {
  28. animation: pulse 2s infinite;
  29. }
  30. @keyframes pulse {
  31. 0% { opacity: 1; }
  32. 50% { opacity: 0.5; }
  33. 100% { opacity: 1; }
  34. }
  35. .gradient-bg {
  36. background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  37. }
  38. .glass-card {
  39. background: rgba(255, 255, 255, 0.8);
  40. backdrop-filter: blur(10px);
  41. border: 1px solid rgba(255, 255, 255, 0.2);
  42. }
  43. .results-container::-webkit-scrollbar {
  44. width: 8px;
  45. }
  46. .results-container::-webkit-scrollbar-track {
  47. background: #f1f1f1;
  48. border-radius: 4px;
  49. }
  50. .results-container::-webkit-scrollbar-thumb {
  51. background: #c7d2fe;
  52. border-radius: 4px;
  53. }
  54. .results-container::-webkit-scrollbar-thumb:hover {
  55. background: #818cf8;
  56. }
  57. </style>
  58. </head>
  59. <body class="min-h-screen py-8">
  60. <div id="app" class="max-w-4xl mx-auto px-4">
  61. <div class="glass-card rounded-2xl shadow-xl overflow-hidden">
  62. <div class="gradient-bg px-6 py-4">
  63. <h1 class="text-2xl font-semibold text-white">视频对象检测</h1>
  64. <p class="text-indigo-100 text-sm mt-1">上传视频并检测其中的特定对象</p>
  65. </div>
  66. <div class="p-6">
  67. <form @submit.prevent="analyzeVideo" class="space-y-6">
  68. <div>
  69. <label class="block text-sm font-medium text-gray-700 mb-2">上传视频</label>
  70. <div class="upload-area rounded-xl p-8 cursor-pointer"
  71. @click="triggerFileInput"
  72. @dragover.prevent="handleDragOver"
  73. @dragleave.prevent="handleDragLeave"
  74. @drop.prevent="handleDrop"
  75. :class="{'border-indigo-500 bg-indigo-50': isDragging}">
  76. <div v-if="!selectedFile" class="text-center">
  77. <svg class="mx-auto h-12 w-12 text-gray-400" stroke="currentColor" fill="none" viewBox="0 0 48 48">
  78. <path d="M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4-4m4-4h.01" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
  79. </svg>
  80. <p class="mt-4 text-sm text-gray-600">点击或拖拽视频文件到此处上传</p>
  81. </div>
  82. <div v-else class="text-center">
  83. <svg class="mx-auto h-12 w-12 text-indigo-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  84. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 4v16M17 4v16M3 8h4m10 0h4M3 12h18M3 16h4m10 0h4M4 20h16a1 1 0 001-1V5a1 1 0 00-1-1H4a1 1 0 00-1 1v14a1 1 0 001 1z"></path>
  85. </svg>
  86. <p class="mt-4 text-sm text-indigo-600">{{ selectedFile.name }}</p>
  87. <p class="text-xs text-gray-500 mt-1">{{ formatFileSize(selectedFile.size) }}</p>
  88. </div>
  89. <input type="file" ref="fileInput" accept="video/*" class="hidden" @change="handleFileChange">
  90. </div>
  91. <p v-if="selectedFile" class="mt-2 text-sm text-indigo-600">已选择文件: {{ selectedFile.name }}</p>
  92. </div>
  93. <div>
  94. <label for="objectInput" class="block text-sm font-medium text-gray-700 mb-2">要查找的对象</label>
  95. <input type="text"
  96. class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition-all"
  97. id="objectInput"
  98. v-model="objectToFind"
  99. placeholder="例如: '穿红色衣服的人'">
  100. </div>
  101. <div v-if="errorMessage" class="rounded-lg bg-red-50 p-4 text-red-700">
  102. {{ errorMessage }}
  103. </div>
  104. <button type="submit"
  105. class="w-full bg-indigo-600 text-white py-2 px-4 rounded-lg hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 transition-all"
  106. :disabled="isAnalyzing"
  107. :class="{'opacity-50 cursor-not-allowed': isAnalyzing}">
  108. {{ isAnalyzing ? '分析中...' : '开始分析' }}
  109. </button>
  110. </form>
  111. <div v-if="isAnalyzing" class="text-center mt-6">
  112. <div class="inline-flex items-center px-4 py-2 bg-indigo-100 text-indigo-700 rounded-full analyzing">
  113. <svg class="animate-spin -ml-1 mr-3 h-5 w-5 text-indigo-700" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
  114. <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
  115. <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
  116. </svg>
  117. 正在分析视频...
  118. </div>
  119. </div>
  120. <div class="results-container mt-6 space-y-4 max-h-[600px] overflow-y-auto pr-2">
  121. <div v-for="(frame, index) in results" :key="index" class="glass-card rounded-xl overflow-hidden">
  122. <div class="p-4 border-b border-gray-100">
  123. <h3 class="font-medium text-gray-900">第 {{ frame.second }} 秒的帧</h3>
  124. </div>
  125. <div class="p-4">
  126. <img :src="frame.frame_path" :alt="'Frame ' + frame.second" class="w-full rounded-lg">
  127. <p class="mt-4 text-gray-700">{{ frame.description || '暂无描述' }}</p>
  128. <div class="mt-4 flex items-center justify-between text-sm text-gray-500">
  129. <span>置信度: {{ frame.confidence }}/10</span>
  130. <span class="px-2 py-1 rounded-full" :class="frame.is_match ? 'bg-green-100 text-green-700' : 'bg-gray-100 text-gray-700'">
  131. {{ frame.is_match ? '匹配' : '不匹配' }}
  132. </span>
  133. </div>
  134. </div>
  135. </div>
  136. </div>
  137. </div>
  138. </div>
  139. </div>
  140. <script>
  141. document.addEventListener('DOMContentLoaded', function() {
  142. new Vue({
  143. el: '#app',
  144. data: {
  145. selectedFile: null,
  146. objectToFind: '',
  147. isAnalyzing: false,
  148. errorMessage: '',
  149. isDragging: false,
  150. results: []
  151. },
  152. methods: {
  153. triggerFileInput() {
  154. this.$refs.fileInput.click();
  155. },
  156. handleFileChange(e) {
  157. if (e.target.files.length) {
  158. const file = e.target.files[0];
  159. if (!file.type.startsWith('video/')) {
  160. this.errorMessage = '请上传有效的视频文件';
  161. return;
  162. }
  163. this.selectedFile = file;
  164. this.errorMessage = '';
  165. }
  166. },
  167. handleDragOver() {
  168. this.isDragging = true;
  169. },
  170. handleDragLeave() {
  171. this.isDragging = false;
  172. },
  173. handleDrop(e) {
  174. this.isDragging = false;
  175. const files = e.dataTransfer.files;
  176. if (files.length) {
  177. const file = files[0];
  178. if (!file.type.startsWith('video/')) {
  179. this.errorMessage = '请上传有效的视频文件';
  180. return;
  181. }
  182. this.selectedFile = file;
  183. this.errorMessage = '';
  184. }
  185. },
  186. formatFileSize(bytes) {
  187. if (bytes === 0) return '0 Bytes';
  188. const k = 1024;
  189. const sizes = ['Bytes', 'KB', 'MB', 'GB'];
  190. const i = Math.floor(Math.log(bytes) / Math.log(k));
  191. return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
  192. },
  193. async analyzeVideo() {
  194. if (!this.selectedFile) {
  195. this.errorMessage = '请选择视频文件';
  196. return;
  197. }
  198. if (!this.objectToFind.trim()) {
  199. this.errorMessage = '请输入要查找的对象描述';
  200. return;
  201. }
  202. this.isAnalyzing = true;
  203. this.errorMessage = '';
  204. this.results = [];
  205. try {
  206. // 这里是模拟API请求,实际使用时替换为真实API调用
  207. // 模拟延迟
  208. await new Promise(resolve => setTimeout(resolve, 1500));
  209. // 模拟返回结果
  210. const mockResults = [
  211. {
  212. second: 5,
  213. frame_path: 'https://via.placeholder.com/640x360?text=视频帧+5秒',
  214. description: '检测到穿红色衣服的人',
  215. confidence: 8,
  216. is_match: true
  217. },
  218. {
  219. second: 12,
  220. frame_path: 'https://via.placeholder.com/640x360?text=视频帧+12秒',
  221. description: '检测到多个对象',
  222. confidence: 5,
  223. is_match: false
  224. }
  225. ];
  226. // 模拟流式响应
  227. for (const result of mockResults) {
  228. await new Promise(resolve => setTimeout(resolve, 500));
  229. this.results.unshift(result);
  230. }
  231. } catch (error) {
  232. console.error('分析错误:', error);
  233. this.errorMessage = '分析过程中发生错误: ' + error.message;
  234. } finally {
  235. this.isAnalyzing = false;
  236. }
  237. }
  238. }
  239. });
  240. });
  241. </script>
  242. </body>
  243. </html>