{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# imports\nimport os\nimport ast\nimport numpy as np \nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport matplotlib.patches as pc\n\nfrom random import choice","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"# set path\ntrain_images_path = \"/kaggle/input/global-wheat-detection/train/\"\ntrain_metadata_path = \"/kaggle/input/global-wheat-detection/train.csv\"\n\n# read metadata\ntrain = pd.read_csv(train_metadata_path)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"## plot image with bboxes and print metadata\n\n# get random image and its metadata\nimage_id = choice(train.image_id)\nimage_metadata = train[train.image_id == image_id]\nimage = plt.imread(\"{}.jpg\".format(train_images_path + image_id))\n\n# plot image with bboxes\nplt.imshow(image)\nfor xmin, ymin, width, height in image_metadata.bbox.apply(lambda x: ast.literal_eval(x)).values:\n    rectangle = pc.Rectangle((xmin,ymin), width, height, fc='none',ec=\"red\")\n    plt.gca().add_patch(rectangle)\nplt.show()\n\nprint(\"> ID of image:\", image_id)\n\nprint(\"> Image width is {} and height is {}\".format(image_metadata.width.values[0], image_metadata.height.values[0]))\n\nprint(\"> Location of the recorded image (aka source):\", image_metadata.source.values[0])\n\n# num objects\nprint(\"> Number of wheat heads in the image:\", image_metadata.shape[0])\n\n# average area of bboxes for this image\nprint(\"> Average area of bounding boxes: {:.2f}\".format(image_metadata.bbox.apply(lambda x: np.prod(ast.literal_eval(x)[2:])).mean()))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}