Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
以圖搜圖系統開發技術分享.pptx.pdf
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
滋滋桑
May 14, 2026
5
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
以圖搜圖系統開發技術分享.pptx.pdf
滋滋桑
May 14, 2026
More Decks by 滋滋桑
See All by 滋滋桑
碳足跡_python.pdf
tzutzu
0
9
以圖搜圖系統開發技術分享.pptx.pdf
tzutzu
0
3
使用JavaScript製作互動式網頁導覽列
tzutzu
0
18
Laravel 8 的使用方式
tzutzu
0
19
SPRING BOOT+VUE+資料庫到底是甚麼
tzutzu
0
65
asp.net用北風資料庫來說明實用技術
tzutzu
0
120
資料庫是什麼
tzutzu
0
43
如何準備證照考試
tzutzu
0
110
準備面試
tzutzu
0
380
Featured
See All Featured
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.5k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
210
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
540
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
720
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
620
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Why Our Code Smells
bkeepers
PRO
340
58k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Leo the Paperboy
mayatellez
7
1.8k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.4k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
Transcript
以圖搜圖系統 開發技術分享 TZU FB-29歲女生學程式
圖⽚上傳與雜湊處理 Controller 實作流程 Image Upload & Hash Processing Logic •
圖片檔案接收與驗證 檔案格式檢查 大小限制控制 • 圖片儲存處理 本地儲存路徑設定 檔名重新命名機制 • DifferenceHash 演算法 圖片縮放與灰階轉換 差異值計算生成雜湊
相似圖⽚搜尋演算法 · 漢明距離計算 ⚙× · ⾨欄值設定 · 資料庫篩選鄭翰 演算法核⼼: 透過漢明距離量化圖⽚相似度,
實現快速且準確的圖⽚匹配 Similar Image Search Algorithm (Hamming Distance Calculation) 比較兩個雜湊值之間的位元差異數量 (Threshold Configuration) 設定相似度判定的臨界值節因 (Database Filtering Logic) 根據計算結果篩選出相似圖片候選
API 路由設定與端點測試 Backend API Configuration & Postman Testing API 路由配置
Postman 功能測試 · 後端路由結構設計 · RESTful API 端點定義 · 請求參數與回應格式 · 鈍誌處理機制 · 圖⽚上傳端點驗證 · 搜尋功能正確性測試 · API 回應時間監控 · 鈍設將態硼驗證 Postman API 測試介⾯展⽰
搜尋精準度與差異判定 關閉成效 測試結果分析 系統判定表現 系統成功識別細微特徵差異,在零件資 料庫中達到⾼精準度匹配,⼤幅提升檢 索效率與準確性 Multiple identical images
search accuracy: 98.5% Subtle difference detection threshold: 0.15 similarity score False positive rate: < 2% Response time: Average 0.3 seconds per query High precision in distinguishing similar components Effective handling of lighting and angle variations Reliable detection of manufacturing differences Consistent results across different image qualities
帶您讀源碼 https://docs.google.com/document/d/1W5YiqlXPjJJ0Hrg7urTRovFSd2X3WgSs/edit?usp=sh aring&ouid=113748954790022803937&rtpof=true&sd=true
測試下載套件: 針對 Laravel 8 使用圖像相似度搜索功能的每一步詳細操作流程,以 jenssegers/imagehash 套件 2.3在VS CODE的地方選終端機 :新終端機
下方終端機執行:
確保已安裝 Laravel 8 環境: bash composer create-project --prefer-dist laravel/laravel="8.*" laravel-image-search
2.4.2安裝圖片哈希套件: bash composer require jenssegers/imagehash 2.4.3如果版本太舊,可以嘗試更新到較新的版本(在 Laravel 8 相容的範圍內): composer update jenssegers/imagehash
下方終端機執行 : bash php artisan make:migration create_images_table --create=images 2.5.2會產生當天的日期在 migrations/2025_09_08_create_images_table.php
裡面的程式碼-變成: <?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class CreateImagetwoTable
extends Migration { /** * Run the migrations. * * @return void */ public function up() { /*Schema::create('imagetwo', function (Blueprint $table) { $table->id(); $table->timestamps();
這段程式碼是一個 Laravel migration,作用是建立 imagetwo 資料表,並定義欄位結構;其中 up() 負責建立表,down() 負責回滾時刪除表。 laravel+1 程式碼用途
CreateImagetwoTable 繼承 Migration,表示 它是資料庫版本控制的一部分,通常會配合 php artisan migrate 執行。stackoverflow+1 當 migration 執行時 ,Schema::create('imagetwo', ...) 會建 立名為 imagetwo 的資料表。laravel 欄位解析 在 Schema::create('imagetwo', function (Blueprint $table) { ... }) 裡,欄位定義 如下:laravel • $table->id();:建立主鍵欄位,通常是 自動遞增的 BIGINT UNSIGNED 主鍵。 laravel • $table->string('path');:建立字串 欄位 path,通常用來存圖片路徑,而且這 個欄位是必填,因為沒有加 nullable()。 stackoverflow+1 • $table->string('image_hash')->nu
None
下面這段 migration 是 Laravel 的標準寫法,我會用「中文+技術說明」一行一行解釋給你。 php <?php PHP 檔案開頭,告訴伺服器這是一個 PHP
檔案。 php use Illuminate\Database\Migrations\Migration; 引入 Laravel 的 Migration 基底類別,這個 migration 會繼承它,讓 Laravel 知道怎麼處理建表、刪表等操作。 php use Illuminate\Database\Schema\Blueprint; 引入 Blueprint 類別,這是用來「描述資料表結構」的物件,像是你在 Schema::create(...) 裡面那個匿名函數裡用 到的 $table。 php use Illuminate\Support\Facades\Schema; 引入 Schema 外觀(Facade),用來呼叫 Schema::create()、Schema::dropIfExists() 這些方法,方便操作資料 庫結構。 php class CreateImagetwoTable extends Migration 宣告一個類別 CreateImagetwoTable,繼承 Laravel 的 Migration,Laravel 會透過檔名判斷這是用來建立 imagetwo 表的 migration。 php
None
到在VS CODE的地方選終端機 :新終端機 下方終端機執行 Migration: bash php artisan migrate
在VS CODE的地方選終端機 :新終端機 下方終端機執行 :建立 Image 模型 bash php artisan
make:model Image
app/Models/ ImageTwo 修改裡面的程式碼 -變成: <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use
Illuminate\Database\Eloquent\Model; class ImageTwo extends Model { use HasFactory; protected $table = 'imagetwo'; // 指定資料表名稱 protected $fillable = ['path', 'image_hash']; }
這段程式碼是在 Laravel 裡建立一個 Eloquent Model,名稱是 ImageTwo,它代表資料庫中的 imagetwo 資料表,並設定哪些欄位可以被大量指定。stackoverflow+1 下面我用逐行方式解釋。laravel php
<?php 這是 PHP 檔案的開頭,表示這份檔案要用 PHP 語法來執行。 php namespace App\Models; 這行宣告命名空間是 App\Models,表示這個 ImageTwo 類別屬於 Laravel 專案中的 Model 目錄結構。 laravel Laravel 預設會把 Eloquent Model 放在 app/Models 底下,所以這樣寫符合框架慣例。laravel php use Illuminate\Database\Eloquent\Factories\HasFactory; 這行引入 HasFactory trait,讓這個 Model 可以搭配 Laravel 的 Factory 功能使用,通常是拿來做測試 資料或假資料產生。stackoverflow 它不是直接拿來連資料庫,而是讓你之後可以方便地建立 model factory。stackoverflow php use Illuminate\Database\Eloquent\Model; 這行引入 Laravel 的 Model 基底類別,因為你的 ImageTwo 要繼承它,才能具有 Eloquent ORM 的功能 ,例如查詢、新增、更新、刪除資料。laravel
None
資料結構的建立 SQL: CREATE TABLE `imagetwo` ( `id` bigint unsigned NOT
NULL AUTO_INCREMENT, `path` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `image_hash` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `created_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL,
建立 Controller(也可以用手動新增 ) 到在VS CODE的地方選終端機 :新終端機 下方終端機執行 bash php artisan
make:controller ImageController
圖片存放的地方 (之後再以公司存放的位置調整 )
ImageTwoController.php 程式碼內容: <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\ImageTwo; use
Jenssegers\ImageHash\ImageHash; use Jenssegers\ImageHash\Implementations\DifferenceHash; class ImageTwoController extends Controller { // 上傳圖片並存資料 public function upload(Request $request) { $request->validate([ 'image' => 'required|image|max:2048', ]); \Log::info('開始上傳流程');
這支 ImageTwoController.php 是一個 Laravel 控制器,主要做兩件事:上傳圖片並存資料 ,以及拿一張 圖片去搜尋相似圖片 。github+1 它也另外寫了一個私有方法,用來在某些情況下手動計算兩個 hash
的漢明距離。stackoverflow+1 類別與引用 php <?php 這是 PHP 檔案開頭,表示接下來的內容使用 PHP 語法。 php namespace App\Http\Controllers; 宣告這個類別位於 App\Http\Controllers 命名空間,也就是 Laravel 專案中控制器的標準位置。laravel php use Illuminate\Http\Request; 引入 Request 類別,用來接收前端送來的 HTTP 請求資料,例如上傳的圖片檔案。laravel php use App\Models\ImageTwo; 引入你前面建立的 ImageTwo model,讓控制器可以把圖片資訊寫入資料庫,或從資料庫讀出已存圖片資 料。laravel php use Jenssegers\ImageHash\ImageHash;
設定 API 路由 用POSTMAN測試: localhost:8000/api/upload
None
搜圖的POSTMAN的測試: localhost:8000/api/search
None