It’s very simple. Use numpy slicing.
import cv2 img = cv2.imread("lenna.png") crop_img = img[y:y+h, x:x+w] cv2.imshow("cropped", crop_img) cv2.waitKey(0)
Related Posts:
- Cannot find module cv2 when using OpenCV
- Cannot find module cv2 when using OpenCV
- How to resize an image with OpenCV2.0 and Python2.6
- ImportError: numpy.core.multiarray failed to import
- import opencv vs import cv2
- Cannot find module cv2 when using OpenCV
- ImportError: DLL load failed: %1 is not a valid Win32 application. But the DLL’s are there
- ImportError: numpy.core.multiarray failed to import
- ImportError: DLL load failed: %1 is not a valid Win32 application. But the DLL’s are there
- Permission denied error by installing matplotlib
- How do I install Python OpenCV through Conda?
- How can I upgrade NumPy?
- Difference in output with waitKey(0) and waitKey(1)
- ImportError: libSM.so.6: cannot open shared object file: No such file or directory
- explain arguments meaning in res = cv2.bitwise_and(img,img,mask = mask)
- OpenCV NoneType object has no attribute shape
- What does bitwise_and operator exactly do in openCV?
- SystemError: new style getargs format but argument is not a tuple?
- ImportError: No module named ‘cv2’ Python3
- Cannot import cv2 in python in OSX
- ImportError: No module named cv2
- OpenCV NoneType object has no attribute shape
- Installing opencv on Windows 10 with python 3.6 and anaconda 3.6
- SystemError: new style getargs format but argument is not a tuple?
- cmake error ‘the source does not appear to contain CMakeLists.txt’
- inverting image in Python with OpenCV
- How does cv2.boundingRect() function of OpenCV work?
- OpenCV houghLinesP parameters
- Python OpenCV2 (cv2) wrapper to get image size?
- ValueError: total size of new array must be unchanged
- Is there a Python equivalent to Ruby’s string interpolation?
- Python Progress Bar
- Most efficient way to find mode in numpy array
- Python error “ImportError: No module named”
- How to groupby based on two columns in pandas?
- How do I append one string to another in Python?
- Python Progress Bar
- How to correct TypeError: Unicode-objects must be encoded before hashing?
- Python: list of lists
- How can I split and parse a string in Python?
- numpy matrix vector multiplication
- whitespace in regular expression
- How do I read CSV data into a record array in NumPy?
- Basic explanation of python functions
- TypeError: ‘Series’ objects are mutable, thus they cannot be hashed problemwith column
- How do I unload (reload) a Python module?
- ImportError: No module named PIL
- Maximum and Minimum values for ints
- How do I list all files of a directory?
- How to check whether a str(variable) is empty or not?
- Clear variable in python
- Python 3.6.0 syntax error “Missing parentheses in call to ‘print’ [duplicate]
- How to get coverage reporting when testing a pytest plugin?
- List of zeros in python
- How to remove an element from a list by index
- How to add title to subplots in Matplotlib
- ‘pip3’ is not recognized as an internal or external command, operable program or batch file
- Apply function to each element of a list
- How to display text in pygame?
- Python Nested Loops To Print Rectangle With Asterisks
- How to fix this strange error: “RuntimeError: CUDA error: out of memory”
- Generate random sentences in python
- Combine two columns of text in pandas dataframe
- How can I rename a conda environment?
- django import error – No module named core.management
- ValueError: unsupported pickle protocol: 3, python2 pickle can not load the file dumped by python 3 pickle?
- Relative paths in Python
- AttributeError(“‘str’ object has no attribute ‘read'”)
- Asyncio.gather vs asyncio.wait
- Loop backwards using indices in Python?
- Why do I get a “referenced before assignment” error when assigning to a global variable in a function?
- What does ‘index 0 is out of bounds for axis 0 with size 0’ mean?
- Generate random colors (RGB)
- Is there a “do … until” in Python?
- Printing variables in Python 3.4
- Meaning of @classmethod and @staticmethod for beginner?
- Haversine Formula in Python (Bearing and Distance between two GPS points)
- Replacing a character from a certain index
- ValueError: Expected object or value when reading json as pandas dataframe
- ImportError: No module named ‘google’
- ‘int’ object has no attribute ‘append’
- What does the “x for x in” syntax mean?
- Numpy extract submatrix
- Repeated “Kernel died, restarting” forever
- TypeError: decoding str is not supported
- Is there a math nCr function in python?
- How to do a Sigma in python 3
- When to use ‘raise NotImplementedError’?
- TypeError: coercing to Unicode: need string or buffer, list found
- Convert string to variable name in python
- Can not click on a Element: ElementClickInterceptedException in Splinter / Selenium
- How to split elements of a list?
- How can I find script’s directory?
- Porting Perl to Python
- Python IOError: File not open for reading
- Strange Exception in Tkinter callback
- How to resolve “ImportError: DLL load failed:” on Python?
- ‘module’ has no attribute ‘urlencode’
- Cannot concatenate ‘str’ and ‘float’ objects?
- Python Text Menu Infinite Loop