Skip to content

Commit

Permalink
完成提取图片数据的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
plter committed Mar 14, 2018
1 parent 55f9d77 commit c562a11
Show file tree
Hide file tree
Showing 106 changed files with 182 additions and 0 deletions.
107 changes: 107 additions & 0 deletions ExtractPhotoData/Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
window.epd = window.epd || {};

(function () {
let urlsString = `0-01.png
0-02.png
0-03.png
0-04.png
0-05.png
0-06.png
0-07.png
0-08.png
0-09.png
0-10.png
1-01.png
1-02.png
1-03.png
1-04.png
1-05.png
1-06.png
1-07.png
1-08.png
1-09.png
1-10.png
2-01.png
2-02.png
2-03.png
2-04.png
2-05.png
2-06.png
2-07.png
2-08.png
2-09.png
2-10.png
3-01.png
3-02.png
3-03.png
3-04.png
3-05.png
3-06.png
3-07.png
3-08.png
3-09.png
3-10.png
4-01.png
4-02.png
4-03.png
4-04.png
4-05.png
4-06.png
4-07.png
4-08.png
4-09.png
4-10.png
5-01.png
5-02.png
5-03.png
5-04.png
5-05.png
5-06.png
5-07.png
5-08.png
5-09.png
5-10.png
6-01.png
6-02.png
6-03.png
6-04.png
6-05.png
6-06.png
6-07.png
6-08.png
6-09.png
6-10.png
7-01.png
7-02.png
7-03.png
7-04.png
7-05.png
7-06.png
7-07.png
7-08.png
7-09.png
7-10.png
8-01.png
8-02.png
8-03.png
8-04.png
8-05.png
8-06.png
8-07.png
8-08.png
8-09.png
8-10.png
9-01.png
9-02.png
9-03.png
9-04.png
9-05.png
9-06.png
9-07.png
9-08.png
9-09.png
9-10.png`;

epd.photoUrls = urlsString.split("\n");

})();
58 changes: 58 additions & 0 deletions ExtractPhotoData/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
(function () {

const BASE_PHOTOS_DIR = "photos";
let canvas = document.createElement("canvas");
let context2d = canvas.getContext("2d");
let train_data_out = document.querySelector("#train_data_out");
let targetDataOut = document.querySelector("#target_data_out");


function initProperties() {
canvas.width = 20;
canvas.height = 20;
}

function loadImage(src) {
return new Promise(((resolve, reject) => {
let img = new Image();
img.onload = () => {
resolve(img);
};
img.src = src;
}));
}

async function main() {
initProperties();


let allPhotoData = [];
let allTargetData = [];
for (let i = 0; i < epd.photoUrls.length; i++) {
let img = await loadImage(`${BASE_PHOTOS_DIR}/${epd.photoUrls[i]}`);

context2d.clearRect(0, 0, canvas.width, canvas.height);
context2d.fillStyle = "#ffffff";
context2d.fillRect(0, 0, canvas.width, canvas.height);
context2d.drawImage(img, 0, 0);

let photoImageData = context2d.getImageData(0, 0, canvas.width, canvas.height);
let photoData = [];
for (let pxIndex = 0; pxIndex < photoImageData.data.length; pxIndex += 4) {
let r = photoImageData.data[pxIndex];
let g = photoImageData.data[pxIndex + 1];
let b = photoImageData.data[pxIndex + 2];
let color = Math.round((r + g + b) / 3);
photoData.push(color);
}
allPhotoData.push(photoData);
allTargetData.push(Math.floor(i / 10));
}

train_data_out.value = JSON.stringify(allPhotoData);
targetDataOut.value = JSON.stringify(allTargetData);
}

main();

})();
1 change: 1 addition & 0 deletions ExtractPhotoData/data/train_data.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ExtractPhotoData/data/train_target.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9]
15 changes: 15 additions & 0 deletions ExtractPhotoData/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<textarea id="train_data_out" style="width: 200px;height: 300px"></textarea>
<textarea id="target_data_out" style="width: 200px;height: 300px"></textarea>


<script src="Data.js"></script>
<script src="app.js"></script>
</body>
</html>
Binary file added ExtractPhotoData/photos/0-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/0-02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/0-03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/0-04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/0-05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/0-06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/0-07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/0-08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/0-09.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/0-10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/1-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/1-02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/1-03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/1-04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/1-05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/1-06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/1-07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/1-08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/1-09.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/1-10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/2-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/2-02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/2-03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/2-04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/2-05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ExtractPhotoData/photos/2-06.png
Binary file added ExtractPhotoData/photos/2-07.png
Binary file added ExtractPhotoData/photos/2-08.png
Binary file added ExtractPhotoData/photos/2-09.png
Binary file added ExtractPhotoData/photos/2-10.png
Binary file added ExtractPhotoData/photos/3-01.png
Binary file added ExtractPhotoData/photos/3-02.png
Binary file added ExtractPhotoData/photos/3-03.png
Binary file added ExtractPhotoData/photos/3-04.png
Binary file added ExtractPhotoData/photos/3-05.png
Binary file added ExtractPhotoData/photos/3-06.png
Binary file added ExtractPhotoData/photos/3-07.png
Binary file added ExtractPhotoData/photos/3-08.png
Binary file added ExtractPhotoData/photos/3-09.png
Binary file added ExtractPhotoData/photos/3-10.png
Binary file added ExtractPhotoData/photos/4-01.png
Binary file added ExtractPhotoData/photos/4-02.png
Binary file added ExtractPhotoData/photos/4-03.png
Binary file added ExtractPhotoData/photos/4-04.png
Binary file added ExtractPhotoData/photos/4-05.png
Binary file added ExtractPhotoData/photos/4-06.png
Binary file added ExtractPhotoData/photos/4-07.png
Binary file added ExtractPhotoData/photos/4-08.png
Binary file added ExtractPhotoData/photos/4-09.png
Binary file added ExtractPhotoData/photos/4-10.png
Binary file added ExtractPhotoData/photos/5-01.png
Binary file added ExtractPhotoData/photos/5-02.png
Binary file added ExtractPhotoData/photos/5-03.png
Binary file added ExtractPhotoData/photos/5-04.png
Binary file added ExtractPhotoData/photos/5-05.png
Binary file added ExtractPhotoData/photos/5-06.png
Binary file added ExtractPhotoData/photos/5-07.png
Binary file added ExtractPhotoData/photos/5-08.png
Binary file added ExtractPhotoData/photos/5-09.png
Binary file added ExtractPhotoData/photos/5-10.png
Binary file added ExtractPhotoData/photos/6-01.png
Binary file added ExtractPhotoData/photos/6-02.png
Binary file added ExtractPhotoData/photos/6-03.png
Binary file added ExtractPhotoData/photos/6-04.png
Binary file added ExtractPhotoData/photos/6-05.png
Binary file added ExtractPhotoData/photos/6-06.png
Binary file added ExtractPhotoData/photos/6-07.png
Binary file added ExtractPhotoData/photos/6-08.png
Binary file added ExtractPhotoData/photos/6-09.png
Binary file added ExtractPhotoData/photos/6-10.png
Binary file added ExtractPhotoData/photos/7-01.png
Binary file added ExtractPhotoData/photos/7-02.png
Binary file added ExtractPhotoData/photos/7-03.png
Binary file added ExtractPhotoData/photos/7-04.png
Binary file added ExtractPhotoData/photos/7-05.png
Binary file added ExtractPhotoData/photos/7-06.png
Binary file added ExtractPhotoData/photos/7-07.png
Binary file added ExtractPhotoData/photos/7-08.png
Binary file added ExtractPhotoData/photos/7-09.png
Binary file added ExtractPhotoData/photos/7-10.png
Binary file added ExtractPhotoData/photos/8-01.png
Binary file added ExtractPhotoData/photos/8-02.png
Binary file added ExtractPhotoData/photos/8-03.png
Binary file added ExtractPhotoData/photos/8-04.png
Binary file added ExtractPhotoData/photos/8-05.png
Binary file added ExtractPhotoData/photos/8-06.png
Binary file added ExtractPhotoData/photos/8-07.png
Binary file added ExtractPhotoData/photos/8-08.png
Binary file added ExtractPhotoData/photos/8-09.png
Binary file added ExtractPhotoData/photos/8-10.png
Binary file added ExtractPhotoData/photos/9-01.png
Binary file added ExtractPhotoData/photos/9-02.png
Binary file added ExtractPhotoData/photos/9-03.png
Binary file added ExtractPhotoData/photos/9-04.png
Binary file added ExtractPhotoData/photos/9-05.png
Binary file added ExtractPhotoData/photos/9-06.png
Binary file added ExtractPhotoData/photos/9-07.png
Binary file added ExtractPhotoData/photos/9-08.png
Binary file added ExtractPhotoData/photos/9-09.png
Binary file added ExtractPhotoData/photos/9-10.png
Binary file modified 机器学习之手写识别.pptx
Binary file not shown.

0 comments on commit c562a11

Please sign in to comment.