Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix something #10

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
4 changes: 4 additions & 0 deletions Aptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
libsm6
libxrender1
libfontconfig1
libice6
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: python server.py
17 changes: 1 addition & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
# miraisai2019_tenji
2019 FUN-AI

## Overview
[これの説明を書く]

## Member
[メンバーを書く]

## Demo
[gif画像を貼る]

## References
[参考情報を書く]


EbichanOO marked this conversation as resolved.
Show resolved Hide resolved
# miraisai2019_tenji
Binary file added __pycache__/face.cpython-36.pyc
Binary file not shown.
Binary file added __pycache__/face.cpython-37.pyc
Binary file not shown.
Binary file added __pycache__/menu.cpython-36.pyc
Binary file not shown.
Binary file added __pycache__/menu.cpython-37.pyc
Binary file not shown.
28 changes: 28 additions & 0 deletions face.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import cv2
import numpy as np
def face_check(img):
# 顔のサイズ最小を定義
face_min_size = (50, 50)

# numpy配列じゃないとopencv対応してないので変換
image = np.array(img)

#グレースケール変換
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

#カスケード分類器の特徴量を取得する
cascade = cv2.CascadeClassifier("./models/haarcascade_frontalface_default.xml")

#物体認識(顔認識)の実行
#image – CV_8U 型の行列.ここに格納されている画像中から物体が検出されます
#objects – 矩形を要素とするベクトル.それぞれの矩形は,検出した物体を含みます
#scaleFactor – 各画像スケールにおける縮小量を表します
#minNeighbors – 物体候補となる矩形は,最低でもこの数だけの近傍矩形を含む必要があります
#flags – このパラメータは,新しいカスケードでは利用されません.古いカスケードに対しては,cvHaarDetectObjects 関数の場合と同じ意味を持ちます
#minSize – 物体が取り得る最小サイズ.これよりも小さい物体は無視されます
facerect = cascade.detectMultiScale(image_gray, scaleFactor=1.1, minNeighbors=2, minSize=face_min_size)

if len(facerect) > 0:
return True
else:
return False
214 changes: 214 additions & 0 deletions menu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
{
"data": [
{
"num": 0,
"next": [
"2",
"3",
"4"
],
"pat": "",
"say_value": "初めまして。何について知りたいですか?聞きたいことを次のメニューから選んでください。"
},
{
"num": 1,
"next": [
"0",
"0",
"0"
],
"pat": "しゅうりょう",
"say_value": "ありがとうございました"
},
{
"num": 2,
"next": [
"0",
"1",
"1"
],
"pat": "わたしについて",
"say_value": "はじめまして。私は、本日みなさんを案内すべく生み出されましたAIです。よろしくおねがいします"
},
{
"num": 3,
"next": [
"5",
"6",
"1"
],
"pat": "みらいさい",
"say_value": "未来祭は今年で20周年を迎えます。毎年、未来祭実行委員の皆さんが準備を頑張ってくれています。"
},
{
"num": 4,
"next": [
"9",
"10",
"1"
],
"pat": "さーくる",
"say_value": "FUN AIは去年発足した新しいサークルなんですよ。人工知能についてみんなで勉強しています"
},
{
"num": 5,
"next": [
"0",
"1",
"1"
],
"pat": "もぎてん",
"say_value": "FUN AIではお菓子のつかみ取りやコーヒーの提供をしています。ぜひ、1階食堂に行ってみてください"
},
{
"num": 6,
"next": [
"7",
"8",
"1"
],
"pat": "ことしのてーま",
"say_value": "今年のテーマはFunfestらしいですよ"
},
{
"num": 7,
"next": [
"0",
"1",
"1"
],
"pat": "もっとてーまのこと",
"say_value": "未来大学を指すFUNとお祭りを指すfestを合わせた言葉で、「未来祭」という意味があるそうですよ"
},
{
"num": 8,
"next": [
"0",
"1",
"1"
],
"pat": "ほんとうのいみ",
"say_value": "Fanfestには親睦会という意味があり、様々な人と親睦を深めてほしいという願いが込められています"
},
{
"num": 9,
"next": [
"11",
"12",
"1"
],
"pat": "どんなさーくる",
"say_value": "毎週2回、みんなで集まって活動を行っています。ふたつの部門があるらしいですよ"
},
{
"num": 10,
"next": [
"0",
"1",
"1"
],
"pat": "うらばなし",
"say_value": "正直、後輩ができるとは思っていなかったそうです。FUN AIは自分の代限りと思っていたらしいですよ"
},
{
"num": 11,
"next": [
"0",
"1",
"1"
],
"pat": "ぶもん",
"say_value": "輪講部門とプログラミング部門があります"
},
{
"num": 12,
"next": [
"0",
"1",
"1"
],
"pat": "せいさくぶつ",
"say_value": "有志で集まって機械学習系のプロダクトを制作する予定らしいですよ"
},
{
"num": 13,
"next": [
"2",
"3",
"1"
],
"pat": "うらばなし",
"say_value": "ここはにほんです"
},
{
"num": 14,
"next": [
"2",
"3",
"1"
],
"pat": "うらばなし",
"say_value": "ここはにほんです"
},
{
"num": 15,
"next": [
"2",
"3",
"1"
],
"pat": "うらばなし",
"say_value": "ここはにほんです"
},
{
"num": 16,
"next": [
"2",
"3",
"1"
],
"pat": "うらばなし",
"say_value": "ここはにほんです"
},
{
"num": 17,
"next": [
"2",
"3",
"1"
],
"pat": "うらばなし",
"say_value": "ここはにほんです"
},
{
"num": 18,
"next": [
"2",
"3",
"1"
],
"pat": "うらばなし",
"say_value": "ここはにほんです"
},
{
"num": 19,
"next": [
"2",
"3",
"1"
],
"pat": "うらばなし",
"say_value": "ここはにほんです"
},
{
"num": 20,
"next": [
"2",
"3",
"1"
],
"pat": "うらばなし",
"say_value": "ここはにほんです"
}
]
}
70 changes: 70 additions & 0 deletions menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import json, codecs
from os import chdir
from pykakasi import kakasi

class Menu:
def __init__(self):
self.switch = None
self.returnmenu = []
# 基本データ構造[[next, pat, say_value], [next, pat, say_value], ...]
self.pat_graph = self.read_json()
self.next_ptr = [0]
self.did_ptr = 0
kakasiKn2H = kakasi()
kakasiKn2H.setMode('J', 'H')
self.kn2hConv = kakasiKn2H.getConverter()
kakasiKt2H = kakasi()
kakasiKt2H.setMode('K', 'H')
self.kt2hConv = kakasiKt2H.getConverter()

def read_json(self):
menu = []
with codecs.open('menu.json', 'r', 'utf-8') as f:
menu_json = json.load(f)
menu_json = menu_json['data']
for i in menu_json:
menu.append([i['next'], i['pat'], i['say_value']])
return menu

def pat_match(self, v, pat=['おはよう', 'こんにちは']):
# パターンに対してマッチングをする、マッチした配列番号を返しマッチングしなければ-1
for i in range(len(pat)):
if pat[i] in v:
return i, True
return self.did_ptr, False

def get_next_pat(self):
pat = []
temp_ptr = []
for i in self.next_ptr:
pat.append(self.pat_graph[i][1])
temp_ptr.append([int(i) for i in self.pat_graph[i][0]])
return pat, temp_ptr

def outmaker(self, num, temp_ptr):
# outputを作成する
# 発言のピックアップ
self.did_ptr = self.next_ptr[num]
say_value = self.pat_graph[self.did_ptr][2]
# 次のパターンのポインタを取得
self.next_ptr = temp_ptr[num]
# 次のパターンの文字列配列を取得
pat, _ = self.get_next_pat()
return say_value, pat

def run(self, v):
v = self.kn2hConv.do(v)
v = self.kt2hConv.do(v)

if self.next_ptr==0:
return self.outmaker(0, self.pat_graph[0][1])
pat , temp_ptr = self.get_next_pat()
num, match_result = self.pat_match(v, pat)

if match_result:
# マッチしたらoutputを作成
return self.outmaker(num, temp_ptr)

# マッチしなかったら過去のpatと発言を送る
return self.pat_graph[num][2], pat

37 changes: 37 additions & 0 deletions menu_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from menu import Menu
import unittest

class MenuTest(unittest.TestCase):

def test_patmatch_short(self):
menu = Menu()
value = 'おはよう'
pat = ['おはよう', 'こんにちは']
self.assertEqual((0, True), menu.pat_match(value, pat))

def test_patmatch_long(self):
menu = Menu()
value = 'どういうこと'
pat = ['おはよう', 'こんにちは', 'さようなら', 'どういうこと', 'さくら']
self.assertEqual((3, True), menu.pat_match(value, pat))

def test_patmatch_InSentence(self):
menu = Menu()
value = 'おはようございます'
pat = ['おはよう', 'こんにちは']
self.assertEqual((0, True), menu.pat_match(value, pat))

def test_read_json(self):
menu = Menu()
value = [["2", "3", "4"], "", "初めまして。何について知りたいですか?"]
self.assertEqual(value, menu.pat_graph[0])

def test_run(self):
menu = Menu()
_, pat = menu.run("")
say, pat = menu.run(pat[0])
self.assertEqual(3, len(pat))


if __name__ == '__main__':
unittest.main()
Loading