Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Extract bounding boxes OpenCV

import cv2

im = cv2.imread('c:/data/ph.jpg')
gray=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
contours, hierarchy = cv2.findContours(gray,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)[-2:]
idx =0 
for cnt in contours:
    idx += 1
    x,y,w,h = cv2.boundingRect(cnt)
    roi=im[y:y+h,x:x+w]
    cv2.imwrite(str(idx) + '.jpg', roi)
    #cv2.rectangle(im,(x,y),(x+w,y+h),(200,0,0),2)
cv2.imshow('img',im)
cv2.waitKey(0)    
Comment

Extract all bounding boxes using OpenCV Python

import cv2

im = cv2.imread('c:/data/ph.jpg')
gray=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
contours, hierarchy = cv2.findContours(gray,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)[-2:]
idx =0 
for cnt in contours:
    idx += 1
    x,y,w,h = cv2.boundingRect(cnt)
    roi=im[y:y+h,x:x+w]
    cv2.imwrite(str(idx) + '.jpg', roi)
    #cv2.rectangle(im,(x,y),(x+w,y+h),(200,0,0),2)
cv2.imshow('img',im)
cv2.waitKey(0)
Comment

PREVIOUS NEXT
Code Example
Python :: pd df rename 
Python :: python datetime get weekday name 
Python :: how to create an entry box on tkinter python 
Python :: django apiview pagination 
Python :: pandas apply lambda function with assign 
Python :: raku fibonacci 
Python :: Python NumPy copyto function example 
Python :: how to print keys and values of dictionary together in python? 
Python :: get last n in array python 
Python :: decimal to octal in python 
Python :: remove in list python 
Python :: find sum numbers in a list in python 
Python :: python 1 line for loop with else 
Python :: Access item in a list of lists 
Python :: sort folders content by name python 
Python :: check if array is monotonic python 
Python :: soup itemprop 
Python :: at=error code=H10 desc="App crashed" django 
Python :: how to get median mode average of a python list 
Python :: in dataframe particular column to string 
Python :: setattr python 
Python :: python remove many items via index at oncefrom a list? 
Python :: df to sql mysql 
Python :: python how to see what pip packages are installed 
Python :: python split string into floats 
Python :: question command python 
Python :: bringing last column to first: Pandas 
Python :: How To Get Redirection URL In Python 
Python :: py hash 
Python :: list comprehension python if else 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =