首页 理论 架构 工程 规划 文档 白皮书 著作 研究 规范 下载 博客 关于 联系 开始使用 →

第四章 图片感知元素模型 Image Perception Element Model

第四章

图片感知元素模型

Image Perception Element Model


4.1 图片在 WSaiOS 感知体系中的定义

图片是人类视觉系统获取外部环境信息的重要方式。

人通过一张图片,可以感知:

  • 物体;
  • 颜色;
  • 形状;
  • 空间位置;
  • 环境结构;
  • 对象关系。

但是,图片本身只是视觉数据。

它并不是认知对象。


WSaiOS 将图片定义为:

图片是一种静态视觉信息载体,通过视觉感知处理后,可以转换为具有对象、属性、状态和关系描述能力的图片感知元素集合。


转换过程:

图片数据 Image Data

↓

图片解析 Image Processing

↓

图片感知元素 Image Perception Elements

↓

认知元素 Cognitive Elements

↓

理解 Understanding

4.2 图片作为静态认知输入

Image as Static Cognitive Input

图片最大的特点:

静态结构表达

它描述:

某一个时间点上的空间状态。


例如:

一张工厂图片:

原始输入:

Image

1920×1080 Pixels

经过视觉解析:

得到:

设备

人员

生产线

区域

进一步形成:

Factory Scene Element

因此:

图片主要提供:

空间信息

包括:

  • 对象存在;
  • 对象位置;
  • 对象形态;
  • 对象关系。

图片不直接表达:

连续变化。

变化需要:

视频元素。


4.3 图片感知元素组成

Structure of Image Perception Element

WSaiOS 将图片转换为元素对象。

基本结构:

Image Element

{

ID

Type

Object

Attribute

State

Position

Relation

Confidence

Function

}

4.3.1 ID(元素标识)

用于唯一识别图片中的元素。

例如:

person_001

machine_001

table_001

作用:

保证元素可追踪。


4.3.2 Type(元素类型)

表示:

元素属于什么类别。

例如:

Person

Vehicle

Device

Animal

Building

Environment

类型决定:

后续认知方式。


例如:

Person:

关注:

  • 身份;
  • 行为;
  • 状态。

Machine:

关注:

  • 工作状态;
  • 故障状态。

4.3.3 Object(对象)

对象是图片元素核心。

表示:

图片中的实体。


例如:

图片:

办公室

对象:

Person

Desk

Computer

Chair

WSaiOS 认为:

视觉系统不是处理像素。

而是发现对象。


4.3.4 Attribute(属性)

属性描述对象特征。


例如:

人物:

Height

Clothing

Color

Shape

汽车:

Brand

Color

Model

设备:

Size

Structure

Material

属性模型:

Object

↓

Attribute Set

数学表示:

A(e)={a1,a2,a3,…,an}A(e)=\{a_1,a_2,a_3,…,a_n\}

其中:

A(e)

表示元素属性集合。


4.3.5 State(状态)

状态描述对象当前情况。


例如:

设备:

Normal

Running

Stopped

Broken

人员:

Standing

Sitting

Walking

状态:

不是固定属性。

而是动态变化。


4.3.6 Position(空间位置)

图片天然包含空间信息。


位置模型:

Position

{

X

Y

Width

Height

Depth

}

例如:

{
"x":100,

"y":200,

"width":80,

"height":180
}

表示:

对象在图片中的位置。


4.3.7 Relation(对象关系)

人理解图片:

不是只看单个对象。

而是理解关系。


例如:

图片:

Person

Computer

Desk

关系:

Person

↓

Using

↓

Computer


Computer

↓

Located_On

↓

Desk

关系模型:

R(e1,e2)R(e_1,e_2)

表示:

元素之间关系。


4.4 图片对象分解模型

Image Object Decomposition Model

复杂图片:

由多个视觉元素组成。


例如:

一张办公室图片:

整体:

Office Image

分解:

Office Scene

├ Person

├ Desk

├ Computer

├ Chair

└ Lighting

对象分解过程:

Image

↓

Region Analysis

↓

Object Detection

↓

Object Elements

4.5 图片属性提取模型

Image Attribute Extraction Model

对象确定以后:

需要提取属性。


过程:

Object

↓

Feature Extraction

↓

Attribute Generation

例如:

检测汽车:

得到:

Object:

Car


Attribute:

Color=Black

Shape=Sedan

State=Stopped

形成:

汽车图片感知元素。


4.6 图片空间关系模型

Spatial Relation Model

空间关系是视觉认知的重要组成。


人看到:

办公室。

不是:

10个物体。

而是:

一个空间场景。


空间关系包括:


1. 位置关系

例如:

Person

Left_of

Computer

2. 距离关系

例如:

Person

Near

Desk

3. 包含关系

例如:

Computer

Inside

Office

4. 拓扑关系

例如:

Room

Connected_With

Hallway

空间关系模型:

Element A

↓

Relation

↓

Element B

4.7 图片场景生成模型

Image Scene Generation Model

单个元素:

不能表达完整环境。

需要组织。


例如:

元素:

Person

Computer

Desk

组织:

Person Using Computer

Computer On Desk

生成:

Office Working Scene

过程:

Image Elements

↓

Element Organization

↓

Relation Construction

↓

Scene Element

4.8 图片场景理解模型

Image Scene Understanding

场景理解是:

从对象到意义的过程。


例如:

图片:

看到:

Person

Laptop

Desk

简单识别:

有人

有电脑

有桌子

场景理解:

这是办公环境

人员正在工作

WSaiOS:

场景理解:

不是依靠概率标签。

而是:

元素+关系+规则。


模型:

Scene=Element+Relation+RuleScene= Element+ Relation+ Rule


4.9 图片元素生成系统模型

WSaiOS 视觉生成系统:

不仅可以理解图片。

也可以根据元素生成图片场景。


核心思想:

图片由元素组合产生。


例如:

创建办公室图片:

元素:

Person

Desk

Computer

Chair

赋值:

Person:

Position=A


Desk:

Position=B


Computer:

On Desk

组合:

生成:

Office Image Scene

模型:

Element Library

↓

Element Parameters

↓

Scene Composition

↓

Image Generation

4.10 图片元素对象化模型

参考面向对象思想:

图片元素:

不是图片碎片。

而是对象。


例如:

class ImageElement
{

    public $type;

    public $attribute;

    public $position;

    public $state;


    public function compose()
    {

    }

}

工程表达:

{
"type":"Tree",

"attribute":{

"color":"green",

"height":"2m"

},

"position":{

"x":100,

"y":300

}

}

这种结构:

可以支持:

  • 图片理解;
  • 图片生成;
  • 场景编辑;
  • 场景模拟。

4.11 本章总结

图片感知元素模型建立:

图片 → 元素 → 场景 → 理解

体系。


核心观点:

  1. 图片是静态视觉输入;
  2. 图片由多个视觉元素组成;
  3. 元素具有属性、状态、位置、关系;
  4. 对象关系形成场景;
  5. 场景组织形成理解;
  6. 元素参数化可以支持图片生成。

最终模型:

Image Data

↓

Image Element

↓

Object Element

↓

Attribute

↓

Spatial Relation

↓

Scene Element

↓

Cognitive Element

下一章:

第五章

视频感知元素模型

Video Perception Element Model

重点:

  • 视频作为动态认知输入;
  • 视频元素组成;
  • 时间连续模型;
  • 行为元素;
  • 事件元素;
  • 状态变化模型;
  • 视频场景理解。

图片感知元素模型工程实现

Image Perception Element Model and PHP OOP MVC Implementation


第四章建立了:

图片 → 元素 → 场景 → 理解

的理论模型。

但是 WSaiOS 的核心目标是:

将图片感知过程转换为面向对象的软件工程模型。

因此:

图片不是文件。

而是:

ImageElement对象集合。


4.12 图片感知元素 OOP 总体模型

理论:

Image Data

↓

Image Element

↓

Object Element

↓

Attribute

↓

Relation

↓

Scene Element

↓

Cognitive Element

转换为软件对象:

ImageFile

↓

ImageElement

↓

VisualObject

↓

AttributeObject

↓

RelationObject

↓

SceneElement

↓

CognitiveObject

整体 Class:

VisualElement


      |

      |

ImageElement


      |

      |

------------------

VisualObject

Attribute

Position

Relation

Scene

------------------

4.13 ImageElement 类设计

图片感知核心对象

目录:

wsaios

/core

 /visual

    ImageElement.php

代码:

<?php


class ImageElement
{


protected $id;


protected $source;


protected $objects=[];


protected $attributes=[];


protected $relations=[];


protected $confidence;



public function __construct($source)
{

    $this->source=$source;

}



public function addObject($object)
{

    $this->objects[]=$object;

}



public function addRelation($relation)
{

    $this->relations[]=$relation;

}



public function analyze()
{

    return [

        "source"=>$this->source,

        "objects"=>$this->objects,

        "relations"=>$this->relations

    ];

}


}

作用:

保存:

  • 图片来源;
  • 对象集合;
  • 属性集合;
  • 关系集合。

4.14 VisualObject对象模型

图片中的对象:

例如:

Person

Computer

Desk

Car

Machine

不是字符串。

而是对象。


设计:

VisualObject

{

id

type

attribute

position

state

}

PHP:

<?php


class VisualObject
{


protected $id;


protected $type;


protected $attributes=[];


protected $position;


protected $state;



public function __construct($type)
{

$this->type=$type;

}



public function addAttribute(
$key,
$value
)
{

$this->attributes[$key]=$value;

}



public function setPosition($position)
{

$this->position=$position;

}



public function setState($state)
{

$this->state=$state;

}


}

例如:

创建:

$person=new VisualObject("Person");


$person->addAttribute(
"clothing",
"uniform"
);


$person->setState(
"working"
);

形成:

Person Object


Type:

Person


Attribute:

Uniform


State:

Working

4.15 图片属性 Attribute 系统设计

视觉对象:

由属性描述。

例如:

汽车:

Car


Color:

Black


Brand:

BMW


State:

Stopped

建立:

AttributeObject

{

name

value

confidence

}

PHP:

class AttributeObject
{


private $name;


private $value;


private $confidence;



public function __construct(
$name,
$value
)
{

$this->name=$name;

$this->value=$value;

}


public function getValue()
{

return $this->value;

}


}

对象关系:

VisualObject

↓

Attribute Collection

↓

Semantic Description

4.16 Position空间坐标模型

图片元素必须知道:

在哪里。


Position对象:

Position

{

x

y

width

height

depth

}

PHP:

class Position
{


protected $x;


protected $y;


protected $width;


protected $height;



public function __construct(
$x,
$y,
$w,
$h
)
{

$this->x=$x;

$this->y=$y;

$this->width=$w;

$this->height=$h;

}


}

例如:

图片:

1920×1080

检测:

人物:

x=300

y=200

width=100

height=300

生成:

Person Position Object

4.17 Relation关系模型

视觉理解核心:

对象之间关系。


例如:

Person

Using

Computer

建立:

VisualRelation

{

source

relation

target

}

PHP:

class VisualRelation
{


protected $source;


protected $relation;


protected $target;



public function __construct(
$source,
$relation,
$target
)
{

$this->source=$source;

$this->relation=$relation;

$this->target=$target;

}


}

使用:

$relation=new VisualRelation(

"Person",

"Using",

"Computer"

);

形成:

视觉知识图:

Person

↓

Using

↓

Computer

4.18 SceneElement场景对象设计

单个对象:

无法形成理解。

需要:

Scene。


例如:

对象:

Person

Desk

Computer

Chair

关系:

Person Using Computer

Computer On Desk

形成:

Office Scene

Class:

class SceneElement
{


protected $name;


protected $objects=[];


protected $relations=[];



public function addObject($object)
{

$this->objects[]=$object;

}



public function addRelation($relation)
{

$this->relations[]=$relation;

}



public function understand()
{


return [

"scene"=>$this->name,

"objects"=>$this->objects

];


}


}

4.19 图片分析 Service层

MVC中:

Model不负责业务。

增加:

Service。

目录:

app

/Services

    ImageAnalysisService.php

代码:

class ImageAnalysisService
{


public function analyze(
ImageElement $image
)
{


$result=
$image->analyze();



return $result;


}


}

流程:

Controller

↓

Service

↓

ImageElement

↓

Object Model

4.20 ImageController设计

目录:

app

/Controllers

ImageController.php

代码:

class ImageController
{


public function upload()
{


$file=$_FILES['image'];



$image=
new ImageElement(
$file['name']
);



$service=
new ImageAnalysisService();



$result=
$service->analyze($image);



return $result;


}


}

完整 MVC:

用户上传图片


↓

Controller


↓

Service


↓

ImageElement


↓

VisualObject


↓

Database


↓

Smarty

4.21 Smarty视觉结果展示

模板:

views

/templates

image.tpl

Smarty:

<h2>
图片分析结果
</h2>


图片:

{$image}


对象:

{$objects}


场景:

{$scene}

显示:

图片:

factory.jpg


识别对象:

Machine

Worker


场景:

Factory Environment

4.22 图片感知数据库设计

图片元素需要长期记忆。

数据库:

image_elements

结构:

字段 说明
id 编号
image_source 图片地址
objects 对象
attributes 属性
relations 关系
scene 场景
confidence 可信度
created_at 时间

SQL:

CREATE TABLE image_elements
(

id INT AUTO_INCREMENT PRIMARY KEY,

image_source VARCHAR(255),

objects TEXT,

attributes TEXT,

relations TEXT,

scene VARCHAR(100),

confidence FLOAT,

created_at TIMESTAMP

);

4.23 图片元素 Memory Engine连接

视觉记忆:

对应人类:

视觉记忆。

WSaiOS:

ImageElement

↓

VisualMemory

↓

ExperienceMemory

↓

CognitiveMemory

例如:

第一次:

看到:

某型号设备

保存:

Machine Pattern

第二次:

再次看到:

类似设备

调用:

Memory Recall

↓

Similarity Match

↓

Cognitive Understanding

4.24 图片元素 Factory设计

未来扩展:

ProductImage

MedicalImage

IndustrialImage

MapImage

统一:

class VisualElementFactory
{


public static function create($type)
{


switch($type)
{


case "image":

return new ImageElement();



case "scene":

return new SceneElement();



}


}


}

4.25 WSaiOS 图片感知模块最终架构

Image Input


↓

ImageController


↓

ImageAnalysisService


↓

ImageElement


↓

VisualObject


↓

Attribute Model


↓

Relation Model


↓

SceneElement


↓

CognitiveElement


↓

Memory Engine


↓

Reasoning Engine

4.26 本章工程总结

第四章完成:

理论模型

图片

↓

对象

↓

属性

↓

关系

↓

场景

↓

理解

OOP模型

ImageElement

↓

VisualObject

↓

AttributeObject

↓

PositionObject

↓

RelationObject

↓

SceneElement

PHP MVC实现

Controller

↓

Service

↓

Model

↓

Repository

↓

Database

↓

Smarty

因此:

WSaiOS 图片感知元素不是图像文件管理系统,而是一个面向对象的视觉认知对象系统。


下一章:

第五章

视频感知元素模型

Video Perception Element Model

重点进入动态视觉:

  1. 视频帧对象模型
  2. FrameElement设计
  3. 时间序列模型
  4. Motion运动元素
  5. Event事件元素
  6. State变化模型
  7. Video MVC工程实现
  8. 视频记忆与经验学习模型

将研究:

静态视觉 → 动态视觉 → 事件认知 → 行为理解。

这一章开始从理论模型进入 PHP OOP 工程实现。

前面的理论回答:

图片如何形成感知元素?

这一章进一步回答:

在 WSaiOS 中,如何用 Class、Model、Service、Controller、Smarty 和数据库,把图片感知元素真正实现出来?

核心对应关系:

人类视觉感知
      ↓
视觉对象识别
      ↓
属性识别
      ↓
空间定位
      ↓
关系建立
      ↓
场景形成
      ↓
WSaiOS Visual Engine
      ↓
PHP OOP Objects
      ↓
MVC
      ↓
Smarty
      ↓
Database

4.27 从理论对象到 PHP 对象

上一节定义了:

Image Element

├ ID
├ Type
├ Object
├ Attribute
├ State
├ Position
├ Relation
├ Confidence
└ Function

在面向对象编程中,它天然对应:

class ImageElement
{
    protected $id;
    protected $type;
    protected $object;
    protected $attributes;
    protected $state;
    protected $position;
    protected $relations;
    protected $confidence;
}

这说明:

WSaiOS 的“元素”理论,可以直接映射为 PHP OOP 中的对象。

但这里需要注意:

ImageElement 不应该承担整个视觉系统。

它只是一个领域对象(Domain Object)。


4.28 WSaiOS Visual Engine 的 OOP 分层

不能把所有代码都写进 ImageElement。

例如下面这种方式不适合:

class ImageElement
{
    public function detect()
    {
        // 图片识别
    }

    public function save()
    {
        // 数据库保存
    }

    public function render()
    {
        // HTML输出
    }
}

这样会把:

领域对象
+
视觉处理
+
数据库
+
页面显示

全部混在一起。

WSaiOS 应该采用:

ImageElement
      ↓
Visual Service
      ↓
Repository
      ↓
Controller
      ↓
Smarty

因此形成:

Model / Domain
Service
Repository
Controller
View

4.29 ImageElement Class 详细设计

首先建立核心对象。

目录:

app/
├── Models/
│   └── Visual/
│       └── ImageElement.php
│
├── Services/
│   └── Visual/
│       ├── ImageElementService.php
│       ├── AttributeService.php
│       ├── PositionService.php
│       ├── RelationService.php
│       └── SceneService.php
│
├── Repositories/
│   └── Visual/
│       └── ImageElementRepository.php
│
├── Controllers/
│   └── Visual/
│       └── ImageController.php
│
└── Views/
    └── visual/
        └── image/
            ├── detail.tpl
            └── scene.tpl

4.30 ImageElement 类

建议第一版:

<?php

class ImageElement
{
    protected $id;

    protected $type;

    protected $object;

    protected $attributes = [];

    protected $state = [];

    protected $position = [];

    protected $relations = [];

    protected $confidence = 0;

    public function __construct(array $data = [])
    {
        $this->id = $data['id'] ?? null;
        $this->type = $data['type'] ?? null;
        $this->object = $data['object'] ?? null;

        $this->attributes = $data['attributes'] ?? [];
        $this->state = $data['state'] ?? [];
        $this->position = $data['position'] ?? [];
        $this->relations = $data['relations'] ?? [];

        $this->confidence = $data['confidence'] ?? 0;
    }

    public function getId()
    {
        return $this->id;
    }

    public function getType()
    {
        return $this->type;
    }

    public function getObject()
    {
        return $this->object;
    }

    public function getAttributes()
    {
        return $this->attributes;
    }

    public function getState()
    {
        return $this->state;
    }

    public function getPosition()
    {
        return $this->position;
    }

    public function getRelations()
    {
        return $this->relations;
    }

    public function getConfidence()
    {
        return $this->confidence;
    }
}

这是最基础的:

视觉元素领域对象。


4.31 为什么使用 Class

WSaiOS 的理论核心之一是:

元素不是简单数据,而是具有结构和行为的信息对象。

因此:

ImageElement

不是:

$data = [];

这么简单。

而应该形成:

Object
│
├ Identity
├ Type
├ Attributes
├ State
├ Position
├ Relations
└ Behavior

这与面向对象思想高度一致。


4.32 Attribute 属性对象

不建议长期使用:

$attributes = [
    'color' => 'black',
    'size' => 'large'
];

作为唯一结构。

随着系统发展,应该逐渐对象化。

建立:

Attribute

类。

<?php

class VisualAttribute
{
    protected $name;

    protected $value;

    protected $type;

    protected $confidence;

    public function __construct(
        $name,
        $value,
        $type = 'string',
        $confidence = 1.0
    ) {
        $this->name = $name;
        $this->value = $value;
        $this->type = $type;
        $this->confidence = $confidence;
    }

    public function getName()
    {
        return $this->name;
    }

    public function getValue()
    {
        return $this->value;
    }

    public function getType()
    {
        return $this->type;
    }

    public function getConfidence()
    {
        return $this->confidence;
    }
}

于是:

ImageElement
      │
      ├── VisualAttribute
      ├── VisualAttribute
      └── VisualAttribute

4.33 Attribute 属性系统

例如一个汽车:

Object
Car

Attributes

color = black
brand = Toyota
shape = sedan
size = medium

PHP:

$car->addAttribute(
    new VisualAttribute(
        'color',
        'black',
        'string',
        0.96
    )
);

因此:

属性
↓
Attribute Object
↓
ImageElement

形成对象组合。


4.34 Position 空间坐标对象

位置也应该对象化。

建立:

<?php

class VisualPosition
{
    protected $x;
    protected $y;
    protected $width;
    protected $height;
    protected $depth;

    public function __construct(
        $x = 0,
        $y = 0,
        $width = 0,
        $height = 0,
        $depth = null
    ) {
        $this->x = $x;
        $this->y = $y;
        $this->width = $width;
        $this->height = $height;
        $this->depth = $depth;
    }

    public function toArray()
    {
        return [
            'x' => $this->x,
            'y' => $this->y,
            'width' => $this->width,
            'height' => $this->height,
            'depth' => $this->depth
        ];
    }
}

4.35 为什么 Position 独立成 Class

因为以后可能出现:

2D Position

x
y
width
height

进一步:

3D Position

x
y
z
width
height
depth

再进一步:

World Coordinate
Camera Coordinate
Image Coordinate
Object Coordinate

所以:

Position

本身就是一个领域对象。


4.36 Relation 关系对象

图片理解的重要部分不是:

Person
Computer
Desk

而是:

Person --Using--> Computer

Computer --On--> Desk

因此建立:

<?php

class VisualRelation
{
    protected $sourceId;

    protected $relation;

    protected $targetId;

    protected $confidence;

    public function __construct(
        $sourceId,
        $relation,
        $targetId,
        $confidence = 1.0
    ) {
        $this->sourceId = $sourceId;
        $this->relation = $relation;
        $this->targetId = $targetId;
        $this->confidence = $confidence;
    }

    public function toArray()
    {
        return [
            'source_id' => $this->sourceId,
            'relation' => $this->relation,
            'target_id' => $this->targetId,
            'confidence' => $this->confidence
        ];
    }
}

这样:

Element A
    ↓
Relation
    ↓
Element B

成为真正的对象关系。


4.37 Relation Graph 关系图

多个元素形成:

Person
   │
   │ Using
   ↓
Computer
   │
   │ On
   ↓
Desk

可以抽象成:

Graph

Nodes
+
Edges

其中:

Node = ImageElement

Edge = VisualRelation

因此:

Image Scene
=
Element Graph

这是后续场景理解的重要基础。


4.38 Scene 场景对象

建立:

<?php

class VisualScene
{
    protected $id;

    protected $type;

    protected $elements = [];

    protected $relations = [];

    protected $environment = [];

    protected $state = [];

    public function __construct($id = null, $type = null)
    {
        $this->id = $id;
        $this->type = $type;
    }

    public function addElement(ImageElement $element)
    {
        $this->elements[] = $element;
    }

    public function addRelation(VisualRelation $relation)
    {
        $this->relations[] = $relation;
    }

    public function getElements()
    {
        return $this->elements;
    }

    public function getRelations()
    {
        return $this->relations;
    }
}

于是:

Image
 │
 ├── ImageElement
 ├── ImageElement
 ├── ImageElement
 │
 ├── VisualRelation
 └── VisualRelation
          ↓
     VisualScene

4.39 Scene 不是简单数组

这是非常重要的工程思想。

不要把场景长期写成:

$scene = [
    'person',
    'desk',
    'computer'
];

而应该:

Scene
│
├ Elements
│
├ Relations
│
├ Environment
│
└ State

因为未来场景需要支持:

查询
分析
比较
更新
记忆
推理
关系计算

4.40 ImageElementService

领域对象建立之后:

由 Service 负责业务处理。

<?php

class ImageElementService
{
    protected $repository;

    public function __construct(
        ImageElementRepository $repository
    ) {
        $this->repository = $repository;
    }

    public function create(array $data)
    {
        $element = new ImageElement($data);

        return $this->repository->save($element);
    }

    public function get($id)
    {
        return $this->repository->find($id);
    }
}

这里体现:

Controller
    ↓
Service
    ↓
Domain Object
    ↓
Repository

4.41 Repository 数据访问层

数据库操作不要放进:

ImageElement

也不要直接放进:

Controller

建立:

class ImageElementRepository
{
    protected $db;

    public function __construct(PDO $db)
    {
        $this->db = $db;
    }

    public function save(ImageElement $element)
    {
        // 数据库存储
    }

    public function find($id)
    {
        // 数据库读取
    }
}

形成:

ImageElement
      ↓
Repository
      ↓
MySQL

4.42 图片感知数据库设计

第一版建议不要把所有内容拆成几十张表。

可以采用:

visual_images
visual_elements
visual_attributes
visual_relations
visual_scenes

visual_images

CREATE TABLE visual_images (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    image_path VARCHAR(500) NOT NULL,
    width INT DEFAULT 0,
    height INT DEFAULT 0,
    source VARCHAR(100) DEFAULT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

visual_elements

CREATE TABLE visual_elements (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    image_id INT UNSIGNED NOT NULL,
    element_type VARCHAR(100) NOT NULL,
    object_name VARCHAR(255) DEFAULT NULL,
    state VARCHAR(100) DEFAULT NULL,
    x DECIMAL(12,4) DEFAULT 0,
    y DECIMAL(12,4) DEFAULT 0,
    width DECIMAL(12,4) DEFAULT 0,
    height DECIMAL(12,4) DEFAULT 0,
    confidence DECIMAL(6,4) DEFAULT 0,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

    INDEX idx_image_id (image_id),
    INDEX idx_element_type (element_type)
);

4.43 visual_attributes

CREATE TABLE visual_attributes (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    element_id INT UNSIGNED NOT NULL,
    attribute_name VARCHAR(100) NOT NULL,
    attribute_value TEXT,
    attribute_type VARCHAR(50) DEFAULT 'string',
    confidence DECIMAL(6,4) DEFAULT 1,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

    INDEX idx_element_id (element_id),
    INDEX idx_attribute_name (attribute_name)
);

4.44 visual_relations

CREATE TABLE visual_relations (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    image_id INT UNSIGNED NOT NULL,
    source_element_id INT UNSIGNED NOT NULL,
    relation_type VARCHAR(100) NOT NULL,
    target_element_id INT UNSIGNED NOT NULL,
    confidence DECIMAL(6,4) DEFAULT 1,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

    INDEX idx_image_id (image_id),
    INDEX idx_source (source_element_id),
    INDEX idx_target (target_element_id)
);

4.45 visual_scenes

CREATE TABLE visual_scenes (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    image_id INT UNSIGNED NOT NULL,
    scene_type VARCHAR(100) DEFAULT NULL,
    scene_name VARCHAR(255) DEFAULT NULL,
    state VARCHAR(100) DEFAULT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

    INDEX idx_image_id (image_id)
);

4.46 数据库与对象的映射

形成:

MySQL

visual_images
       ↓
Image

visual_elements
       ↓
ImageElement

visual_attributes
       ↓
VisualAttribute

visual_relations
       ↓
VisualRelation

visual_scenes
       ↓
VisualScene

这就是:

数据库记录 → PHP OOP 对象 → WSaiOS 感知元素。


4.47 Visual Engine

现在开始出现真正的:

WSaiOS Visual Engine

建议目录:

engine/
└── Visual/
    ├── ImageElement.php
    ├── VisualAttribute.php
    ├── VisualPosition.php
    ├── VisualRelation.php
    ├── VisualScene.php
    │
    ├── ImageParser.php
    ├── ObjectDetector.php
    ├── AttributeExtractor.php
    ├── RelationBuilder.php
    ├── SceneBuilder.php
    └── VisualAnalyzer.php

这里可以看出:

Element
Parser
Detector
Extractor
Relation
Scene
Analyzer

已经形成一个独立的视觉子系统。


4.48 ImageParser

class ImageParser
{
    public function parse($image)
    {
        return [
            'width' => 1920,
            'height' => 1080,
            'source' => $image
        ];
    }
}

注意:

这里暂时不实现真正的视觉算法。

这是工程架构研究。

也就是说:

ImageParser

负责:

输入标准化。


4.49 ObjectDetector

class ObjectDetector
{
    public function detect(array $imageData)
    {
        return [
            [
                'type' => 'Person',
                'confidence' => 0.95
            ],
            [
                'type' => 'Computer',
                'confidence' => 0.91
            ],
            [
                'type' => 'Desk',
                'confidence' => 0.94
            ]
        ];
    }
}

这里以后可以接:

规则引擎
传统算法
外部视觉模型
可选AI Adapter

但:

ImageElement 本身不应该知道检测技术是什么。


4.50 AttributeExtractor

class AttributeExtractor
{
    public function extract(array $object)
    {
        return [
            'color' => 'black',
            'size' => 'medium'
        ];
    }
}

形成:

Object
   ↓
AttributeExtractor
   ↓
Attributes

4.51 RelationBuilder

class RelationBuilder
{
    public function build(array $elements)
    {
        $relations = [];

        // 根据空间位置和规则建立关系

        return $relations;
    }
}

例如规则:

如果:

A.x < B.x

则:

A LeftOf B

或者:

如果:

Distance(A,B) < threshold

则:

A Near B

这就是 WSaiOS 的:

元素 + 规则 → 关系


4.52 SceneBuilder

class SceneBuilder
{
    public function build(
        array $elements,
        array $relations
    ) {
        $scene = new VisualScene(
            null,
            'Office'
        );

        foreach ($elements as $element) {
            $scene->addElement($element);
        }

        foreach ($relations as $relation) {
            $scene->addRelation($relation);
        }

        return $scene;
    }
}

形成:

Elements
+
Relations
↓
Scene

4.53 完整 Visual Pipeline

最终:

Image
 ↓
ImageParser
 ↓
ObjectDetector
 ↓
ImageElement
 ↓
AttributeExtractor
 ↓
VisualAttribute
 ↓
RelationBuilder
 ↓
VisualRelation
 ↓
SceneBuilder
 ↓
VisualScene

这就是:

WSaiOS Visual Engine v1


4.54 MVC 层如何接入

现在进入 MVC。

目录:

app/
│
├── Controllers/
│   └── Visual/
│       └── ImageController.php
│
├── Models/
│   └── Visual/
│       └── ImageElement.php
│
├── Services/
│   └── Visual/
│       └── ImageService.php
│
├── Repositories/
│   └── Visual/
│       └── ImageRepository.php
│
└── Views/
    └── visual/
        └── image/
            └── detail.tpl

4.55 ImageController

Controller 不负责视觉算法。

只负责:

接收请求
↓
调用 Service
↓
准备 View 数据
↓
Smarty 输出

例如:

class ImageController
{
    protected $service;

    protected $smarty;

    public function __construct(
        ImageService $service,
        Smarty $smarty
    ) {
        $this->service = $service;
        $this->smarty = $smarty;
    }

    public function detail($id)
    {
        $scene = $this->service->analyze($id);

        $this->smarty->assign(
            'scene',
            $scene
        );

        $this->smarty->display(
            'visual/image/detail.tpl'
        );
    }
}

4.56 Smarty 的位置

Smarty 不参与:

视觉识别

也不参与:

数据库操作

Smarty 只负责:

View

即:

VisualScene
      ↓
Smarty
      ↓
HTML

4.57 Smarty 模板

例如:

<h1>图片感知场景</h1>

<div class="scene">

    <div>
        场景类型:
        {$scene->getType()}
    </div>

    <h2>视觉元素</h2>

    {foreach $scene->getElements() as $element}

        <div class="element">

            <strong>
                {$element->getType()}
            </strong>

            <div>
                Object:
                {$element->getObject()}
            </div>

            <div>
                Confidence:
                {$element->getConfidence()}
            </div>

        </div>

    {/foreach}

</div>

这样:

PHP Object
      ↓
Smarty
      ↓
HTML

4.58 MVC 完整链路

用户访问:

/visual/image/100

系统:

Router
  ↓
ImageController
  ↓
ImageService
  ↓
VisualEngine
  ↓
ImageElement
  ↓
Relation
  ↓
Scene
  ↓
Smarty
  ↓
HTML

数据库:

Repository
   ↕
MySQL

因此完整结构:

                 WSaiOS Visual Engine
                         │
              ┌──────────┴──────────┐
              ↓                     ↓
          ImageElement          VisualScene
              │                     │
              ↓                     ↓
          Repository             Service
              │                     │
              ↓                     ↓
            MySQL              Controller
                                    │
                                    ↓
                                  Smarty
                                    │
                                    ↓
                                   HTML

4.59 为什么 MVC 对 WSaiOS 很重要

WSaiOS 不是简单 PHP 页面。

它实际上正在形成:

认知系统

因此必须把:

认知对象
算法
数据
控制
显示

分离。

MVC/OOP 提供了这种工程分离。


4.60 人类视觉皮层 → Visual Engine

这里需要做一个非常重要的理论限定:

WSaiOS 不是生物神经系统的复制品。

而是:

用软件对象和信息处理流程,对人类认知过程进行工程抽象。

可以建立对应关系:

人类视觉过程 WSaiOS 工程抽象
视觉输入 ImageParser
视觉特征处理 Feature/Attribute Service
对象识别 ObjectDetector
空间定位 VisualPosition
对象关系 VisualRelation
场景组织 VisualScene
视觉记忆 VisualMemory
经验形成 ExperienceEngine
认知输入 CognitiveElement

因此:

人类视觉系统
       ↓
视觉信息处理
       ↓
对象
       ↓
关系
       ↓
场景
       ↓
理解

抽象为:

WSaiOS Visual Input
       ↓
ImageParser
       ↓
ImageElement
       ↓
VisualRelation
       ↓
VisualScene
       ↓
CognitiveElement

4.61 图片感知 → CognitiveElement

这是本章最重要的出口。

视觉系统最终不能停留在:

Person
Computer
Desk

而需要交给:

Cognitive Engine

例如:

VisualScene

Office

Person
Computer
Desk

Person Using Computer

经过:

Semantic Mapping

形成:

CognitiveElement

type = WorkingActivity

subject = Person

object = Computer

context = Office

于是:

Visual Engine
      ↓
Cognitive Engine

正式连接起来。


4.62 第一版工程目录

综合起来,可以形成:

wsaios/
│
├── app/
│   │
│   ├── Controllers/
│   │   └── Visual/
│   │       └── ImageController.php
│   │
│   ├── Models/
│   │   └── Visual/
│   │       ├── ImageElement.php
│   │       ├── VisualAttribute.php
│   │       ├── VisualPosition.php
│   │       ├── VisualRelation.php
│   │       └── VisualScene.php
│   │
│   ├── Services/
│   │   └── Visual/
│   │       ├── ImageService.php
│   │       ├── AttributeService.php
│   │       ├── RelationService.php
│   │       └── SceneService.php
│   │
│   ├── Repositories/
│   │   └── Visual/
│   │       └── ImageElementRepository.php
│   │
│   └── Views/
│       └── visual/
│           └── image/
│               ├── detail.tpl
│               └── scene.tpl
│
├── engine/
│   └── Visual/
│       ├── ImageParser.php
│       ├── ObjectDetector.php
│       ├── AttributeExtractor.php
│       ├── RelationBuilder.php
│       ├── SceneBuilder.php
│       └── VisualAnalyzer.php
│
├── config/
│   └── database.php
│
└── public/
    └── index.php

4.63 本章形成的 OOP 对象体系

最终形成:

VisualElement
      │
      ├── ImageElement
      │
      ├── VisualAttribute
      │
      ├── VisualPosition
      │
      ├── VisualRelation
      │
      └── VisualScene

处理体系:

ImageParser
      ↓
ObjectDetector
      ↓
AttributeExtractor
      ↓
RelationBuilder
      ↓
SceneBuilder
      ↓
VisualAnalyzer

应用体系:

Controller
      ↓
Service
      ↓
Engine
      ↓
Repository
      ↓
Database

显示体系:

Controller
      ↓
Smarty
      ↓
HTML

4.64 本章核心工程结论

到这里,第四章已经从单纯的“视觉理论”进入了真正的:

WSaiOS Visual OOP Architecture

核心关系可以压缩成:

             IMAGE
               │
               ↓
         ImageParser
               │
               ↓
        ObjectDetector
               │
               ↓
        ImageElement
          /    |    \
         /     |     \
 Attribute  Position  State
         \     |     /
          \    |    /
           Relation
               │
               ↓
          VisualScene
               │
               ↓
        CognitiveElement
               │
               ↓
        Cognitive Engine

而 PHP MVC 则负责把它工程化:

                 WSaiOS
                   │
        ┌──────────┴──────────┐
        │                     │
   Visual Engine         Cognitive Engine
        │
   ┌────┴────┐
   │         │
 Domain    Service
 Objects      │
   │          │
   └────┬─────┘
        │
   Repository
        │
      MySQL
        │
   Controller
        │
     Smarty
        │
       View

这一步非常关键:

WSaiOS 的“元素理论”不再只是概念模型,而开始变成:

Class → Object → Service → Repository → Controller → Smarty → Database

的一套可以实际编码的认知工程结构。

下一步第五章可以按照同样方法继续,但重点转向动态视觉:

ImageElement
      ↓
FrameElement
      ↓
FrameSequence
      ↓
MotionElement
      ↓
EventElement
      ↓
StateTransition
      ↓
BehaviorElement
      ↓
CognitiveEvent

也就是从**“看见一个对象”正式进入“看见一个对象发生了什么”**。

Leave a Reply

Your email address will not be published. Required fields are marked *

客服咨询
● 欢迎咨询与合作
您好!欢迎咨询。 我可以帮助您了解人工智能技术研发、智能软件系统开发、网站建设、搜索优化及项目定制等相关信息。 请问有什么可以帮您?
免费申请
请填写以下信息,方便我们进一步沟通。
欢迎咨询 AI 系统开发、网站建设、搜索优化、项目定制合作
电话:15089196448
邮箱:1602401899@qq.com
地址:陕西省渭南市
服务时间:周一至周五 09:00 - 18:00 | 7×24小时技术值守