Skip to content

Commit 4b752c1

Browse files
Document updated on repair (#5)
* 文档更新 * 更新其中的1.17版本官方文档 * 开始新版本1.18的开发 开始开发任务 * update * 新增矩阵 AGG 函数的逻辑实现 * update * 新增边框对象 * update * update * 完善模板匹配函数的实现,增加步长,提升效率。 * update * update * 矩阵开始被归一化计算组件支持 * Update Case.md * update * 针对图像矩阵进行了合并功能的更新 * 针对IO数据流进行了优化。 * update * 为AS库添加第三方数据源支持,并允许通过摄像头获取到图像数据 * update * update * update * 更新HDFS数据IO组件 * update * 1.18版本发布 * 1.18版本发布,新版本已发布至maven * update log * 更新日志中英文文档链接 * update * 格式化文档 * Update Case.md * Update Case.md
1 parent e1cc557 commit 4b752c1

File tree

5 files changed

+89
-57
lines changed

5 files changed

+89
-57
lines changed

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ requires importing log dependencies, which are essential. Please import the depe
5757
<!--<scope>provided</scope>-->
5858
</dependency>
5959
<!-- Log4j2 log real surface -->
60+
6061
<dependency>
6162
<groupId>org.apache.logging.log4j</groupId>
6263
<artifactId>log4j-core</artifactId>
@@ -81,12 +82,14 @@ need to, you can refer to the following configuration.
8182
<artifactId>mysql-connector-java</artifactId>
8283
<version>8.0.30</version>
8384
</dependency>
85+
8486
<!-- The dependency development package for the three major Spark modules can also be imported if you need to use it here, or not if you don't need it -->
8587
<dependency>
8688
<groupId>org.apache.spark</groupId>
8789
<artifactId>spark-core_2.12</artifactId>
8890
<version>3.1.3</version>
8991
</dependency>
92+
9093
<dependency>
9194
<groupId>org.apache.spark</groupId>
9295
<artifactId>spark-sql_2.12</artifactId>
@@ -106,13 +109,13 @@ need to, you can refer to the following configuration.
106109
<version>0.3.12</version>
107110
</dependency>
108111

109-
<!-- HDFS input/output device dependency library. If you have a need for data reading and writing through the HDFS distributed storage platform, you can introduce this library. -->
110-
<dependency>
111-
<groupId>org.apache.hadoop</groupId>
112-
<artifactId>hadoop-client</artifactId>
113-
<version>3.3.1</version>
114-
</dependency>
115-
112+
<!-- HDFS input/output device dependency library. If you have a need for data reading and writing through the HDFS distributed storage platform, you can introduce this library. -->
113+
<dependency>
114+
<groupId>org.apache.hadoop</groupId>
115+
<artifactId>hadoop-client</artifactId>
116+
<version>3.3.1</version>
117+
</dependency>
118+
116119
</dependencies>
117120
```
118121

src_code/Case.md

Lines changed: 59 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ public class MAIN1 {
112112

113113
### 图像模板匹配
114114

115-
- 人脸识别 通过人脸模板匹配曼哈顿相似系数
115+
- 人脸识别
116+
117+
通过人脸模板匹配曼哈顿相似系数,进而得出人脸识别结果,在这里我们需要使用以下的图像作为样本,需要注意的是,该样本的轮廓为黑色,适用于背光情况下的人脸识别操作。
118+
119+
![YB](https://user-images.githubusercontent.com/113756063/230775389-4477aad4-795c-47c2-a946-0afeadafad44.jpg)
116120

117121
```java
118122
package zhao.algorithmMagic;
@@ -173,7 +177,8 @@ import java.util.Map;
173177
public class MAIN1 {
174178
public static void main(String[] args) {
175179
ColorMatrix colorMatrix1, colorMatrix2;
176-
{ // 将图像与样本读取进来
180+
{
181+
// 将图像与样本读取进来
177182
colorMatrix1 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\YB.bmp");
178183
colorMatrix2 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test22.jpg");
179184
ColorMatrix temp = ColorMatrix.parse(colorMatrix2.copyToNewArrays());
@@ -216,7 +221,7 @@ public class MAIN1 {
216221
```
217222

218223
```java
219-
package zhao.algorithmMagic;
224+
package zhao.run;
220225

221226
import zhao.algorithmMagic.algorithm.distanceAlgorithm.ManhattanDistance;
222227
import zhao.algorithmMagic.io.InputCamera;
@@ -227,50 +232,59 @@ import zhao.algorithmMagic.operands.matrix.ColorMatrix;
227232
import zhao.algorithmMagic.operands.table.FinalCell;
228233

229234
import java.awt.*;
235+
import java.net.MalformedURLException;
236+
import java.net.URL;
230237
import java.util.Map;
231238

232-
public class MAIN1 {
233-
public static void main(String[] args) {
234-
ColorMatrix colorMatrix1, colorMatrix2;
235-
{
236-
// 获取到摄像头输入设备
237-
InputComponent inputComponent = InputCamera.builder()
238-
// 要使用的摄像头的名字 索引 或def默认,我们这里使用的是 def 代表使用默认摄像头
239-
.addInputArg(InputCameraBuilder.Camera_Index, new FinalCell<>("def"))
240-
// 要使用的拍摄图像格式
241-
.addInputArg(InputCameraBuilder.Image_Format, new FinalCell<>("JPG"))
242-
// 图像尺寸 这里的数值是 WebcamResolution 枚举类的属性字段 VGA
243-
.addInputArg(InputCameraBuilder.CUSTOM_VIEW_SIZES, new FinalCell<>("VGA"))
244-
.create();
245-
// 将图像与样本读取进来
246-
colorMatrix1 = ColorMatrix.parse("C:\\Users\\liming\\Desktop\\fsdownload\\YB.bmp");
247-
colorMatrix2 = ColorMatrix.parse(inputComponent);
248-
ColorMatrix temp = ColorMatrix.parse(colorMatrix2.copyToNewArrays());
249-
// 开始二值化
250-
colorMatrix1.localBinary(ColorMatrix._G_, 10, 0xffffff, 0, 1);
251-
temp.localBinary(ColorMatrix._G_, 5, 0xffffff, 0, 20);
252-
temp.erode(2, 2, false);
253-
temp.show("temp");
254-
// 开始进行模板匹配 并返回最匹配的结果数值,在这里返回的就是所有匹配的结果数据,key为匹配系数 value为匹配结果
255-
Map.Entry<Double, IntegerCoordinateTwo> matching = temp.templateMatching(
256-
ManhattanDistance.getInstance("MAN"),
257-
colorMatrix1,
258-
ColorMatrix._G_,
259-
10,
260-
false
261-
);
262-
// 开始进行绘制 在这里首先获取到坐标数据
263-
IntegerCoordinateTwo coordinateTwo = matching.getValue();
264-
System.out.print("匹配系数 = ");
265-
System.out.println(matching.getKey());
266-
colorMatrix2.drawRectangle(
267-
coordinateTwo,
268-
new IntegerCoordinateTwo(coordinateTwo.getX() + colorMatrix1.getColCount(), coordinateTwo.getY() + colorMatrix1.getRowCount()),
269-
Color.MAGENTA
270-
);
271-
}
272-
colorMatrix1.show("人脸样本");
273-
colorMatrix2.show("识别结果");
239+
public class Test {
240+
public static void main(String[] args) throws MalformedURLException {
241+
// 获取到摄像头数据据输入设备对象
242+
InputComponent inputComponent = InputCamera.builder()
243+
.addInputArg(InputCameraBuilder.Camera_Index, new FinalCell<>(0))
244+
.addInputArg(InputCameraBuilder.Image_Format, new FinalCell<>("JPG"))
245+
.create();
246+
// 解析人脸轮廓样本,作为模板
247+
ColorMatrix parse = ColorMatrix.parse(
248+
new URL("https://user-images.githubusercontent.com/113756063/230775389-4477aad4-795c-47c2-a946-0afeadafad44.jpg")
249+
);
250+
// 从摄像头中读取一个图像,并将其加载成图像矩阵,并且进行一个备份操作。
251+
ColorMatrix colorMatrix1 = ColorMatrix.parse(inputComponent);
252+
ColorMatrix colorMatrix2 = ColorMatrix.parse(colorMatrix1.copyToNewArrays());
253+
// 接下来针对 colorMatrix1 对象进行二值化,用于降低颜色对于结果的影响
254+
colorMatrix1.localBinary(
255+
// 二值化计算时需要使用的颜色通道
256+
ColorMatrix._G_,
257+
// 二值化计算时,由于采取的是局部二值化,需要指定子矩阵数量,在这里指定为10
258+
10,
259+
// 当颜色大于局部阈值的时候要变更的颜色数值
260+
0xffffff,
261+
// 当颜色小于局部阈值的时候要变更的颜色数值
262+
0,
263+
// 指定二值化操作时,所有局部颜色阈值的偏置
264+
1
265+
);
266+
// 二值化结束就可以开始进行模板匹配了 匹配之后会返回一个最相似的矩阵的匹配系数以及左上角坐标
267+
Map.Entry<Double, IntegerCoordinateTwo> entry = colorMatrix1.templateMatching(
268+
// 指定需要进行模板匹配的算法
269+
ManhattanDistance.getInstance("MAN"),
270+
// 指定模板 也就是人脸样本数据
271+
parse,
272+
// 指定计算时使用的颜色通道
273+
ColorMatrix._G_,
274+
// 指定卷积步长,步长越大性能越高,越小精准度越高
275+
12,
276+
// 指定 相似系数 与 相似程度是否成正相关性 这里由于我们使用的时曼哈顿,因此为负相关,填 false
277+
false
278+
);
279+
// 获取到左上角坐标
280+
IntegerCoordinateTwo l = entry.getValue();
281+
// 计算出右下角坐标
282+
IntegerCoordinateTwo r = new IntegerCoordinateTwo(
283+
l.getX() + parse.getColCount(), l.getY() + parse.getRowCount()
284+
);
285+
// 绘制到备份的原矩阵并展示图像
286+
colorMatrix2.drawRectangle(l, r, new Color(255, 0, 255));
287+
colorMatrix2.show("image");
274288
}
275289
}
276290
```

src_code/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55

66
<groupId>io.github.BeardedManZhao</groupId>

src_code/src/main/java/zhao/algorithmMagic/operands/vector/SparkVector.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,21 @@ final class SparkVector(sparkContext: SparkContext, vector: org.apache.spark.mll
107107
else throw new OperatorOperationException("'DoubleVector1 add DoubleVector2' 时,两个'DoubleVector'的向量所包含的数量不同,DoubleVector1=[" + numberOfDimensions1 + "],DoubleVector2=[" + numberOfDimensions2 + "]\n" + "When 'DoubleVector1 add DoubleVector2', the two vectors of 'DoubleVector' contain different quantities, DoubleVector1=[" + numberOfDimensions1 + "], DoubleVector2=[" + numberOfDimensions2 + "]")
108108
}
109109

110+
/**
111+
*
112+
* @return 将本对象中存储的向量序列数组拷贝到一个新数组并将新数组返回,这里返回的是一个新数组,支持修改等操作。
113+
*
114+
* Copy the vector sequence array stored in this object to a new array and return the new array. Here, a new array is returned, which supports modification and other operations.
115+
*/
116+
override def copyToNewArray(): Array[Double] = vector.toArray
117+
118+
/**
119+
* @return 向量中包含的维度数量
120+
* <p>
121+
* the number of dimensions contained in the vector
122+
*/
123+
override def getNumberOfDimensions: Int = size
124+
110125
/**
111126
* 在两个操作数之间做差的方法,具体用法请参阅API说明。
112127
* <p>

src_code/src/main/resources/log4j2.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<Appenders>
1616
<!-- 控制台输出 appender,SYSTEM_OUT输出黑色,SYSTEM_ERR输出红色 -->
1717
<Console name="Console" target="SYSTEM_OUT">
18-
<PatternLayout pattern="[%p][%c][%d{yy-MM-dd:hh}]] : %m%n" />
18+
<PatternLayout pattern="[%p][%c][%d{yy-MM-dd:hh}]] : %m%n"/>
1919
</Console>
2020

2121
<!-- &lt;!&ndash; 日志文件输出 appender &ndash;&gt;-->
@@ -25,7 +25,7 @@
2525

2626
<!-- 使用随机读写流的日志文件输出 appender,性能提高 -->
2727
<RandomAccessFile name="accessFile" fileName="${LOG_HOME}/algorithmStar.log">
28-
<PatternLayout pattern="[%p][%c][%d{yy-MM-dd:hh:mm:ss}]] : %m%n" />
28+
<PatternLayout pattern="[%p][%c][%d{yy-MM-dd:hh:mm:ss}]] : %m%n"/>
2929
</RandomAccessFile>
3030
</Appenders>
3131

@@ -34,8 +34,8 @@
3434
<!-- 使用 rootLogger 配置 日志级别 level="info" -->
3535
<Root level="info">
3636
<!-- 指定日志使用的处理器 -->
37-
<AppenderRef ref="Console" />
38-
<AppenderRef ref="accessFile" />
37+
<AppenderRef ref="Console"/>
38+
<AppenderRef ref="accessFile"/>
3939
</Root>
4040
</Loggers>
4141
</configuration>

0 commit comments

Comments
 (0)