|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 3, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [ |
| 8 | + { |
| 9 | + "ename": "error", |
| 10 | + "evalue": "OpenCV(4.10.0) D:\\a\\opencv-python\\opencv-python\\opencv\\modules\\imgproc\\src\\smooth.dispatch.cpp:617: error: (-215:Assertion failed) !_src.empty() in function 'cv::GaussianBlur'\n", |
| 11 | + "output_type": "error", |
| 12 | + "traceback": [ |
| 13 | + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", |
| 14 | + "\u001b[1;31merror\u001b[0m Traceback (most recent call last)", |
| 15 | + "Cell \u001b[1;32mIn[3], line 7\u001b[0m\n\u001b[0;32m 4\u001b[0m img \u001b[38;5;241m=\u001b[39m cv2\u001b[38;5;241m.\u001b[39mimread(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdatasets\u001b[39m\u001b[38;5;130;01m\\\\\u001b[39;00m\u001b[38;5;124maalesund\u001b[39m\u001b[38;5;130;01m\\\\\u001b[39;00m\u001b[38;5;124m1504200\u001b[39m\u001b[38;5;130;01m\\\\\u001b[39;00m\u001b[38;5;124m200.jpg\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;241m0\u001b[39m)\n\u001b[0;32m 6\u001b[0m \u001b[38;5;66;03m# Apply Gaussian Blur to reduce noise\u001b[39;00m\n\u001b[1;32m----> 7\u001b[0m blurred_img \u001b[38;5;241m=\u001b[39m \u001b[43mcv2\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mGaussianBlur\u001b[49m\u001b[43m(\u001b[49m\u001b[43mimg\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m5\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m5\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m 9\u001b[0m \u001b[38;5;66;03m# Apply adaptive thresholding to separate background and foreground\u001b[39;00m\n\u001b[0;32m 10\u001b[0m threshold_img \u001b[38;5;241m=\u001b[39m cv2\u001b[38;5;241m.\u001b[39madaptiveThreshold(blurred_img, \u001b[38;5;241m255\u001b[39m, cv2\u001b[38;5;241m.\u001b[39mADAPTIVE_THRESH_GAUSSIAN_C, \n\u001b[0;32m 11\u001b[0m cv2\u001b[38;5;241m.\u001b[39mTHRESH_BINARY, \u001b[38;5;241m11\u001b[39m, \u001b[38;5;241m2\u001b[39m)\n", |
| 16 | + "\u001b[1;31merror\u001b[0m: OpenCV(4.10.0) D:\\a\\opencv-python\\opencv-python\\opencv\\modules\\imgproc\\src\\smooth.dispatch.cpp:617: error: (-215:Assertion failed) !_src.empty() in function 'cv::GaussianBlur'\n" |
| 17 | + ] |
| 18 | + } |
| 19 | + ], |
| 20 | + "source": [ |
| 21 | + "import cv2\n", |
| 22 | + "\n", |
| 23 | + "# Load the scanned map\n", |
| 24 | + "img = cv2.imread('datasets\\\\aalesund\\\\1504200\\\\200.jpg', 0)\n", |
| 25 | + "\n", |
| 26 | + "# Apply Gaussian Blur to reduce noise\n", |
| 27 | + "blurred_img = cv2.GaussianBlur(img, (5, 5), 0)\n", |
| 28 | + "\n", |
| 29 | + "# Apply adaptive thresholding to separate background and foreground\n", |
| 30 | + "threshold_img = cv2.adaptiveThreshold(blurred_img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, \n", |
| 31 | + " cv2.THRESH_BINARY, 11, 2)\n", |
| 32 | + "\n", |
| 33 | + "# Display the processed image\n", |
| 34 | + "cv2.imshow('Processed Image', threshold_img)\n", |
| 35 | + "cv2.waitKey(0)\n", |
| 36 | + "cv2.destroyAllWindows()\n" |
| 37 | + ] |
| 38 | + } |
| 39 | + ], |
| 40 | + "metadata": { |
| 41 | + "kernelspec": { |
| 42 | + "display_name": "Python 3", |
| 43 | + "language": "python", |
| 44 | + "name": "python3" |
| 45 | + }, |
| 46 | + "language_info": { |
| 47 | + "codemirror_mode": { |
| 48 | + "name": "ipython", |
| 49 | + "version": 3 |
| 50 | + }, |
| 51 | + "file_extension": ".py", |
| 52 | + "mimetype": "text/x-python", |
| 53 | + "name": "python", |
| 54 | + "nbconvert_exporter": "python", |
| 55 | + "pygments_lexer": "ipython3", |
| 56 | + "version": "3.12.1" |
| 57 | + } |
| 58 | + }, |
| 59 | + "nbformat": 4, |
| 60 | + "nbformat_minor": 2 |
| 61 | +} |
0 commit comments