{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import cv2\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3.3.0\n" ] } ], "source": [ "print(cv2.__version__)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "img = np.full((210, 425, 3), 128, dtype=np.uint8)\n", "\n", "cv2.rectangle(img, (50, 10), (125, 60), (255, 0, 0))\n", "cv2.rectangle(img, (50, 80), (125, 130), (0, 255, 0), thickness=-1)\n", "cv2.rectangle(img, (50, 150), (125, 200), (0, 0, 255), thickness=-1)\n", "cv2.rectangle(img, (50, 150), (125, 200), (255, 255, 0))\n", "\n", "cv2.rectangle(img, (175, 10), (250, 60), (255, 255, 255), thickness=8, lineType=cv2.LINE_4)\n", "cv2.line(img, (175, 10), (250, 60), (0, 0, 0), thickness=1, lineType=cv2.LINE_4)\n", "cv2.rectangle(img, (175, 80), (250, 130), (255, 255, 255), thickness=8, lineType=cv2.LINE_8)\n", "cv2.line(img, (175, 80), (250, 130), (0, 0, 0), thickness=1, lineType=cv2.LINE_8)\n", "cv2.rectangle(img, (175, 150), (250, 200), (255, 255, 255), thickness=8, lineType=cv2.LINE_AA)\n", "cv2.line(img, (175, 150), (250, 200), (0, 0, 0), thickness=1, lineType=cv2.LINE_AA)\n", "\n", "cv2.rectangle(img, (600, 20), (750, 120), (0, 0, 0), lineType=cv2.LINE_AA, shift=1)\n", "cv2.rectangle(img, (601, 160), (751, 260), (0, 0, 0), lineType=cv2.LINE_AA, shift=1)\n", "cv2.rectangle(img, (602, 300), (752, 400), (0, 0, 0), lineType=cv2.LINE_AA, shift=1)\n", "\n", "cv2.imwrite('data/dst/opencv_draw_argument.png', img)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n" ] } ], "source": [ "img_rect = cv2.rectangle(img, (10, 10), (110, 60), (255, 0, 0))\n", "print(img is img_rect)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "img = np.full((210, 425, 3), 128, dtype=np.uint8)\n", "\n", "cv2.line(img, (50, 10), (125, 60), (255, 0, 0))\n", "cv2.line(img, (50, 60), (125, 10), (0, 255, 255), thickness=4, lineType=cv2.LINE_AA)\n", "\n", "cv2.arrowedLine(img, (50, 80), (125, 130), (0, 255, 0), thickness=4)\n", "cv2.arrowedLine(img, (50, 130), (125, 80), (255, 0, 255), tipLength=0.3)\n", "\n", "cv2.rectangle(img, (50, 150), (125, 200), (255, 255, 0))\n", "\n", "cv2.circle(img, (190, 35), 15, (255, 255, 255), thickness=-1)\n", "cv2.circle(img, (240, 35), 20, (0, 0, 0), thickness=3, lineType=cv2.LINE_AA)\n", "\n", "cv2.ellipse(img, ((190, 105), (20, 50), 0), (255, 255, 255))\n", "cv2.ellipse(img, ((240, 105), (20, 50), 30), (0, 0, 0), thickness=-1)\n", "\n", "cv2.ellipse(img, (190, 175), (10, 25), 0, 0, 270, (255, 255, 255))\n", "cv2.ellipse(img, (240, 175), (10, 25), 30, 0, 270, (0, 0, 0), thickness=-1)\n", "\n", "cv2.drawMarker(img, (300, 20), (255, 0, 0))\n", "cv2.drawMarker(img, (337, 20), (0, 255, 0), markerType=cv2.MARKER_TILTED_CROSS, markerSize=15)\n", "cv2.drawMarker(img, (375, 20), (0, 0, 255), markerType=cv2.MARKER_STAR, markerSize=10)\n", "\n", "cv2.drawMarker(img, (300, 50), (0, 255, 255), markerType=cv2.MARKER_DIAMOND)\n", "cv2.drawMarker(img, (337, 50), (255, 0, 255), markerType=cv2.MARKER_SQUARE, markerSize=15)\n", "cv2.drawMarker(img, (375, 50), (255, 255, 0), markerType=cv2.MARKER_TRIANGLE_UP, markerSize=10)\n", "\n", "pts = np.array(((300, 80), (300, 130), (335, 130)))\n", "cv2.polylines(img, [pts], True, (255, 255, 255), thickness=2)\n", "\n", "pts = np.array(((335, 80), (375, 80), (375, 130)))\n", "cv2.fillPoly(img, [pts], (0, 0, 0))\n", "\n", "cv2.putText(img, 'nkmk', (300, 170), cv2.FONT_HERSHEY_SIMPLEX, 1.0, (255, 255, 255), thickness=2)\n", "cv2.putText(img, 'nkmk', (300, 195), cv2.FONT_HERSHEY_COMPLEX, 0.8, (0, 0, 0), lineType=cv2.LINE_AA)\n", "\n", "cv2.imwrite('data/dst/opencv_draw_etc.png', 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.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }