How to crop an image with Python + OpenCV

Personal memorandum & Qiita post test

Original image

lena.jpg

Trim


import cv2

#Load and resize images
pic_url = "lena.jpg "
img = cv2.imread(pic_url)

#Image matrix[Y coordinate at the top of the rectangle:Y coordinate at the bottom of the rectangle,X coordinate on the left side of the rectangle:X coordinate on the right side of the rectangle]
cut_img = img[0:200,0:200]

while True:
    cv2.imshow("img", cut_img)
    #If the q key is pressed, it ends halfway
    if cv2.waitKey(25) & 0xFF == ord('q'):
        cv2.destroyAllWindows()
        break

result

スクリーンショット 2020-03-23 22.14.28.png

The point is

Image matrix [y-coordinate at the top of the rectangle: y-coordinate at the bottom of the rectangle, x-coordinate at the left of the rectangle: x-coordinate at the right of the rectangle]

Is that the place?

Recommended Posts

How to crop an image with Python + OpenCV
How to crop the lower right part of the image with Python OpenCV
I tried to make an image similarity function with Python + OpenCV
[Python] How to handle Japanese characters with openCV
Post an article with an image to WordPress with Python
Image editing with python OpenCV
How to scrape image data from flickr with python
How to create an image uploader in Bottle (Python)
Cut out an image with python
Python: How to use async with
[Python] Using OpenCV with Python (Image Filtering)
[Python] Using OpenCV with Python (Image transformation)
How to get started with Python
How to use FTP with Python
How to calculate date with python
Find image similarity with Python + OpenCV
Draw an illustration with Python + OpenCV
Introduction to image analysis opencv python
How to convert an array to a dictionary with Python [Application]
How to run an app built with Python + py2app built with Anaconda
[Python Kivy] How to create an exe file with pyinstaller
How to read an Excel file (.xlsx) with Pandas [Python]
A story about how Windows 10 users created an environment to use OpenCV3 with Python 3.5
HTML email with image to send with python
python3 How to install an external module
Introduction to Python Image Inflating Image inflating with ImageDataGenerator
How to work with BigQuery in Python
Image processing with Python & OpenCV [Tone Curve]
How to do portmanteau test with python
Image acquisition from camera with Python + OpenCV
How to check opencv version in python
How to display python Japanese with lolipop
How to adjust image contrast in Python
How to enter Japanese with Python curses
[Python] How to deal with module errors
Try to generate an image with aliasing
Light image processing with Python x OpenCV
How to install python3 with docker centos
Sample to convert image to Wavelet with Python
How to make a surveillance camera (Security Camera) with Opencv and Python
Try to extract a character string from an image with Python3
How to create a heatmap with an arbitrary domain in Python
[Python] Explains how to use the format function with an example
How to use an external editor for Python development with Grasshopper
How to upload with Heroku, Flask, Python, Git (4)
I tried "smoothing" the image with Python + OpenCV
How to read a CSV file with Python 2/3
How to enjoy programming with Minecraft (Ruby, Python)
[REAPER] How to play with Reascript in Python
How to do multi-core parallel processing with python
Convert PDF to image (JPEG / PNG) with Python
How to install Python
Strategy on how to monetize with Python Java
How to install OpenCV on Jetson Nano Python
I tried "differentiating" the image with Python + OpenCV
Binarization with OpenCV / Python
Send an email to Spushi's address with python
How to use Python Image Library in python3 series
[Python] How to draw multiple graphs with Matplotlib
[Python] How to read excel file with pandas
How to install python