-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uploading all the source and other solution files.
- Loading branch information
1 parent
292c8f9
commit bcca8fc
Showing
10 changed files
with
70,179 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import flask\n", | ||
"from flask import request, jsonify\n", | ||
"import sqlite3\n", | ||
"\n", | ||
"app = flask.Flask(__name__)\n", | ||
"app.config[\"DEBUG\"] = True\n", | ||
"\n", | ||
"def dict_factory(cursor, row):\n", | ||
" d = {}\n", | ||
" for idx, col in enumerate(cursor.description):\n", | ||
" d[col[0]] = row[idx]\n", | ||
" return d\n", | ||
"\n", | ||
"\n", | ||
"@app.route('/', methods=['GET'])\n", | ||
"def home():\n", | ||
" return '''<h1>Distant Reading Archive</h1>\n", | ||
"<p>A prototype API for distant reading of science fiction novels.</p>'''\n", | ||
"\n", | ||
"\n", | ||
"@app.route('/api/v1/resources/books/all', methods=['GET'])\n", | ||
"def api_all():\n", | ||
" conn = sqlite3.connect('books.db')\n", | ||
" conn.row_factory = dict_factory\n", | ||
" cur = conn.cursor()\n", | ||
" all_books = cur.execute('SELECT * FROM books;').fetchall()\n", | ||
"\n", | ||
" return jsonify(all_books)\n", | ||
"\n", | ||
"\n", | ||
"\n", | ||
"@app.errorhandler(404)\n", | ||
"def page_not_found(e):\n", | ||
" return \"<h1>404</h1><p>The resource could not be found.</p>\", 404\n", | ||
"\n", | ||
"\n", | ||
"@app.route('/api/v1/resources/books', methods=['GET'])\n", | ||
"def api_filter():\n", | ||
" query_parameters = request.args\n", | ||
"\n", | ||
" id = query_parameters.get('id')\n", | ||
" published = query_parameters.get('published')\n", | ||
" author = query_parameters.get('author')\n", | ||
"\n", | ||
" query = \"SELECT * FROM books WHERE\"\n", | ||
" to_filter = []\n", | ||
"\n", | ||
" if id:\n", | ||
" query += ' id=? AND'\n", | ||
" to_filter.append(id)\n", | ||
" if published:\n", | ||
" query += ' published=? AND'\n", | ||
" to_filter.append(published)\n", | ||
" if author:\n", | ||
" query += ' author=? AND'\n", | ||
" to_filter.append(author)\n", | ||
" if not (id or published or author):\n", | ||
" return page_not_found(404)\n", | ||
"\n", | ||
" query = query[:-4] + ';'\n", | ||
"\n", | ||
" conn = sqlite3.connect('books.db')\n", | ||
" conn.row_factory = dict_factory\n", | ||
" cur = conn.cursor()\n", | ||
"\n", | ||
" results = cur.execute(query, to_filter).fetchall()\n", | ||
"\n", | ||
" return jsonify(results)\n", | ||
"\n", | ||
"app.run()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import cv2\n", | ||
"\n", | ||
"face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')\n", | ||
"eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')\n", | ||
"\n", | ||
"cap = cv2.VideoCapture(0)\n", | ||
"\n", | ||
"while True:\n", | ||
" ret, img = cap.read()\n", | ||
" gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n", | ||
" faces = face_cascade.detectMultiScale(gray, 1.3, 5)\n", | ||
"\n", | ||
" for (x, y, w, h) in faces:\n", | ||
" cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)\n", | ||
" roi_gray = gray[y:y + h, x:x + w]\n", | ||
" roi_color = img[y:y + h, x:x + w]\n", | ||
"\n", | ||
" eyes = eye_cascade.detectMultiScale(roi_gray)\n", | ||
" for (ex, ey, ew, eh) in eyes:\n", | ||
" cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 2)\n", | ||
"\n", | ||
" cv2.imshow('img', img)\n", | ||
" k = cv2.waitKey(30) & 0xff\n", | ||
" if k == 27:\n", | ||
" break\n", | ||
"\n", | ||
"cap.release()\n", | ||
"cv2.destroyAllWindows()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from fer import FER\n", | ||
"import matplotlib.pyplot as plt \n", | ||
"img = plt.imread(\"happy.jpg\")\n", | ||
"detector = FER(mtcnn=True)\n", | ||
"print(detector.detect_emotions(img))\n", | ||
"plt.imshow(img)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from fer import Video\n", | ||
"from fer import FER\n", | ||
"video_filename = \"D:/python/YouTube.mp4\"\n", | ||
"video = Video(video_filename)\n", | ||
"# Analyze video, displaying the output\n", | ||
"detector = FER(mtcnn=True)\n", | ||
"video.analyze(detector, display=True)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
"# DCod.X" | ||
"# DCod.X" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"cells": [], | ||
"metadata": {}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import cv2\n", | ||
"from fer import FER\n", | ||
"detector = FER(mtcnn=True) \n", | ||
"image = cv2.imread(\"andrew_ng.jpg\")\n", | ||
"result = detector.detect_emotions(image)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
Oops, something went wrong.