current position:Home>Learning in Python + opencv -- extracting corners
Learning in Python + opencv -- extracting corners
2022-01-30 02:33:20 【kobesdu】
- Little knowledge , Great challenge ! This article is participating in “ A programmer must have a little knowledge ” Creative activities .
Realize the function of extracting contour , And draw the center of gravity of the outline
import numpy as np
import cv2
from pylab import imshow
from pylab import array
from pylab import plot
from pylab import title
# Read the picture
img = cv2.imread('timg.jpeg')
img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)# To gray value
# Two valued ,canny testing
binaryImg = cv2.Canny(img,50,200)
# Look for the outline
contours,contourstype=cv2.findContours(binaryImg,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
# Check the number of contours
-- print (len(contours))
--print (type(contours))
-- print (type(contourstype))
--print ((contourstype))
temp = np.ones(binaryImg.shape,np.uint8)*255
for each in contours:
M = cv2.moments(each)# Moment of contour
Copy code
( stay OpenCV in , It is very convenient to calculate the of polygon area 3 First order characteristic moment ,opencv The moments in mainly include the following : Space moment , Central moment and central normalized moment .)
if (M['m00']!=0):
cx = int(M['m10']/M['m00'])# Calculate the center of gravity
cy = int(M['m01']/M['m00'])
pos=(cx,cy)
print(pos)
cv2.circle(temp,pos, 4, (0, 0, 0), 4)# Draw the center point of the contour
(img Pointer to the source image ; The first parameter is the coordinates of the center of the circle ; The second parameter is the radius of the circle ; The third is to set the color of the circle , Rule basis B( blue )G( green )R( red ) The fourth one s If the parameter is a positive number , Indicates the thickness of the lines that make up the circle . otherwise , Indicates whether the circle is filled )
Copy code
# Draw the outline :temp It's a white curtain ,contours It's the outline ,-1 It means the whole picture , Then the color , The thickness of the
cv2.drawContours(temp,contours,-1,(0,255,0),3)
( Draw external and internal contours in the image ; Among them, Dangdang thickness >= 0 when , Draw contours ; Otherwise, fill the part surrounded by the contour ..)
cv2.imshow("contours",temp)
cv2.waitKey(0)
cv2.destroyAllWindows()
About drawContours Reference resources blog.csdn.net/fulva/artic… About drawing circle function reference blog.csdn.net/yangfengman…
copyright notice
author[kobesdu],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201300233183693.html
The sidebar is recommended
- Install tensorflow and python 3.6 in Windows 7
- Python collects and monitors system data -- psutil
- Getting started with Python - object oriented - special methods
- Teach you how to use Python to transform an alien invasion game
- You can easily get started with Excel. Python data analysis package pandas (VI): sorting
- Implementation of top-level design pattern in Python
- Using linear systems in python with scipy.linalg
- How to get started quickly? How to learn Python
- Modifying Python environment with Mac OS security
- Better use atom to support jupyter based Python development
guess what you like
-
Better use atom to support jupyter based Python development
-
Fast power modulus Python implementation of large numbers
-
Python architects recommend the book "Python programmer's Guide" which must be read by self-study Python architects. You are welcome to take it away
-
Decoding the verification code of Taobao slider with Python + selenium, the road of information security
-
Python game development, pyGame module, python implementation of skiing games
-
Python collects and monitors system data -- psutil
-
Python + selenium automated test: page object mode
-
You can easily get started with Excel. Python data analysis package pandas (IV): any grouping score bar
-
Opencv skills | saving pictures in common formats as transparent background pictures (with Python source code) - teach you to easily make logo
-
Python ThreadPoolExecutor restrictions_ work_ Queue size
Random recommended
- Python generates and deploys verification codes with one click (Django)
- With "Python" advanced, you can catch all the advanced syntax! Advanced function + file operation, do not look at regret Series ~
- At the beginning of "Python", you must see the series. 10000 words are only for you. It is recommended to like the collection ~
- [Python kaggle] pandas basic exercises in machine learning series (6)
- Using linear systems in python with scipy.linalg
- The founder of pandas teaches you how to use Python for data analysis (mind mapping)
- Using Python to realize national second-hand housing data capture + map display
- Python image processing, automatic generation of GIF dynamic pictures
- Pandas advanced tutorial: time processing
- How to make Python run faster? Six tips!
- Django: use of elastic search search system
- Python 3.10 official release
- Python chat room (Tkinter writing interface, streaming, socket to realize private chat, group chat, check chat records, Mysql to store data)
- This pandas exercise must be successfully won
- [algorithm learning] sword finger offer 64 Find 1 + 2 +... + n (Java / C / C + + / Python / go / trust)
- leetcode 58. Length of Last Word(python)
- Problems encountered in writing the HTML content of articles into the database during the development of Django blog
- Understand Python's built-in function and add a print function yourself
- Python implements JS encryption algorithm in thousands of music websites
- leetcode 35. Search Insert Position(python)
- leetcode 1829. Maximum XOR for Each Query(python)
- [introduction to Python visualization]: 12 small examples of complete data visualization, taking you to play with visualization ~
- Learning this Python library can reduce at least 100 lines of code
- leetcode 67. Add Binary(python)
- Regular re parameter replacement of Python 3 interface automation test framework
- V. pandas based on Python
- Only 15 lines of code is needed for face detection! (using Python and openCV)
- [Python crawler Sao operation] you can crawl Sirius cinema movies without paying
- leetcode 69. Sqrt(x)(python)
- Teach you to read the source code of Cpython (I)
- Snowball learning started in the fourth quarter of Python. One needs three meals. I have a new understanding of Python functional programming, process-oriented, object-oriented and functional
- leetcode 88. Merge Sorted Array(python)
- Don't you know more about a python library before the end of 2021?
- Python crawler web page parsing artifact XPath quick start teaching!!!
- Use Python and OpenCV to watermark the image
- String and related methods of Python data type introduction
- Heapq module of Python module
- Introduction to beautiful soup of Python crawler weapon, detailed explanation, actual combat summary!!!
- Event loop of Python collaboration series
- Django docking pin login system