computer-vision/vision.ipynb

160 lines
300 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### vision"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7f50f04e1210>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAW8AAAD8CAYAAAC4uSVNAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8li6FKAAAgAElEQVR4nOy8ya4l23ae980yyhVrrV1mnsxzbkHSggi7R0oUQMqwDBmSO27bD6Bn8Au477Yabvsd3KBAuWWZgAhaAikWl+fkyWoXq4o6ZqVG7HtIA6QNAb7WJZR/b8eOFRFzzDFHjPmPf4RIKfEFX/AFX/AFf7sg/2M/wBd8wRd8wRf8h+NL8P6CL/iCL/hbiC/B+wu+4Au+4G8hvgTvL/iCL/iCv4X4Ery/4Au+4Av+FuJL8P6CL/iCL/hbiF9Y8BZC/BMhxB8LIf5UCPE//qLu8wVf8AVf8J8ixC9C5y2EUMC/A/4x8D3wr4D/PqX0b/8/v9kXfMEXfMF/gvhFZd5/D/jTlNKfp5QW4H8F/rtf0L2+4Au+4Av+k4P+BV33DfDur/z9PfD3/6aTM2tTVZUIIRBCEoInhIiQAhJoo0kpIgASJAHeB6SQQEJK+fKPxBIiQoCWihAjAEYrfAiEEJFSooQkwg/XjCSU1EgBPnikkCRACkFKAqUEKUVCTCglSSmxLB6lJDFGpFQ/HI8xIITEKEUiAQofFkCQ0npPYH0OKVmcAwQCgVSSFCNKK0IIAGgpQUAIkYRAivW5IIEQgERKSUzr+asZElKK/5uNhZAIISBFnA9opYgp8XIlYvzL30ilSfHleiRiTA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Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"from matplotlib import pyplot as plt\n",
"\n",
"import vision.io\n",
"from vision.descriptor.avg_RGB import extract_average_rgb\n",
"from vision.visualsearch import run_query\n",
"\n",
"x = vision.io.load_msrc('msrc/Images')\n",
"extract_average_rgb(images=x)\n",
"results = run_query(x)\n",
"plt.imshow(results.query_image.pixels)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.06465854988522113"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"results.precision_recall.ap"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4\n"
]
},
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7f35401c9a90>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD7CAYAAABzGc+QAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8li6FKAAAgAElEQVR4nOy9W6wt2XWeN2ZVrbX3ufbpPn3jpZtNSpRIkbqQtmUZSgTBiiMjMiInDoTYgqEkAvTiGAmSIJLzlJcAyUsSPQUg7AQKYMB2YgMyYCEOoEAPCQLFlKOLKUrirZvse5/7be+9VlXNPMz/G/NyTh9SbDLem5rj4ayz16pVNWvWrFX/GOMf/wgxRuvWrVu3bmfPhn/ZA+jWrVu3bt+c9R/wbt26dTuj1n/Au3Xr1u2MWv8B79atW7czav0HvFu3bt3OqPUf8G7dunU7o/Zt+QEPIfzFEMIfhhC+GEL4pW/HMbp169btT7qFbzUPPIQwmtkfmdlfMLNXzeyf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Narne+01hi9PXJ/8xMhCa3jUayzXUb0O/COupedpeJXXnRNYOs+aeQQSx/gZIhKwCpk7M6sY0+TrqKnpcLKNzk+/yDM1bI9hoJh1BN6tW7duZ9ZOCQKPto6L5UI4suI8rRR/VTXWBrRDXK1gV1DxBWqY/CkLJxQYS7wwVp8vjlLIjtfPOJ7auxxQ1IHrTHdccxx1HECfxNXrMmBKlk8GeL3aJahmrHm5Y4PcgdOLM0vqslxnHRRP8wGUqfPz0nhno2g
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"import cv2\n",
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"\n",
"import vision.descriptor.spatial as spatial\n",
"\n",
"img = cv2.imread('sheep.png')[:,:,::-1]\n",
"\n",
"segments = spatial.grid_image(2, 2, img)\n",
"print(len(segments))\n",
"plt.imshow(segments[0])"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import cv2\n",
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"\n",
"import vision.descriptor.spatial as spatial\n",
"\n",
"img = cv2.imread('sheep.png')[:,:,::-1]\n",
"\n",
"segments = spatial.extract_spatial_average_rgb(2, 2, 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.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 4
}