[PYTHON] Remove the frame from the image

Preparation

import cv2
import matplotlib.pyplot as plt

processing

#Load image
img = cv2.imread("〜〜〜.png ")
#Grayscale the image
img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
#Display image
plt.imshow(img_gray)
plt.gray()

How to recognize table cells in OpenCV

You can use it by tweaking the numbers of edge extraction and the truncation of min size.

Introduction to image processing: Image processing starting with OpenCV and Python

Extract contour
image, contours, hierarchy = cv2.findContours(img_gray,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
#Draw on img2
img2 = cv2.drawContours(img_gray, contours, -1, (0,255,0), 3)
#Display and save img2
plt.imshow(img2)
cv2.imwrite('img2.png', img2)
plt.gray()

contours are contours, hierachy is contour hierarchy information

Explanation about cv2.findContours and cv2.drawContours ↓ Outline: First Step

Grayscale with Python

[Introduction to Python] Complete understanding of decimal point operations from rounding up to round!

[Python] Get the maximum and minimum values of the list and their indexes (max, min, index)

Connect images vertically and horizontally with Python, OpenCV (hconcat, vconcat, np.tile)

Recommended Posts

Remove the frame from the image
Let's cut the face from the image
Download the image from the text file containing the URL
Extracted text from image
[Python] How to remove duplicate values from the list
I tried to detect the iris from the camera image
[Python] Specify the range from the image by dragging the mouse
Save the input video from the capture board as an image
Let's search from the procession
Dot according to the image
Extract only the cat part from the cat image (matting / semantic segmentation)
I tweeted from the terminal!
Let's guess the development status of the city from the satellite image.
The image is a slug
Do a search by image from the camera roll using Pythonista3
[Python] Try to graph from the image of Ring Fit [OCR]
I tried to cut out a still image from the video
Make a Santa classifier from a Santa image
Detect mosaic points in the image
Automatically generate collage from image list
Existence from the viewpoint of Python
Use the Flickr API from Python
Gender is determined from the name.
Get the value from the [Django] Form
Remove unknown plugins in the scene
Learn from the winning code-Mercari Competition ①-
Try blurring the image with opencv2
Image processing | predicting species from images
Get the address from the zip code
Judge the extension and download the image
Remove and retrieve arrays from fasta according to the ID list file
[python] Send the image captured from the webcam to the server and save it