计算机视觉课_计算机视觉教程—第4课
計算機視覺課
Note from author :
作者注:
This tutorial is the foundation of computer vision delivered as “Lesson 3” of the series, there are more Lessons upcoming which would talk to the extend of building your own deep learning based computer vision projects. You can find the complete syllabus and table of content here
本教程是本系列“第3課”中提供的計算機視覺的基礎,接下來將有更多課程與構建基于深度學習的計算機視覺項目相關。 您可以在此處找到完整的課程提綱和目錄
Target Audience : Final year College Students, New to Data Science Career, IT employees who wants to switch to data science Career .
目標受眾 :最后一年的大學生,數據科學職業新手,想要轉用數據科學職業的IT員工。
Takeaway : Main takeaway from this article :
外賣 :本文的主要外賣:
形態運算 (Morphological operations)
Morphological operations are simple transformations applied to binary images. More specifically, we apply morphological operations to shapes and structures inside of images.
形態學運算是應用于二進制圖像的簡單轉換。 更具體地說,我們將形態學運算應用于圖像內部的形狀和結構 。
We can use morphological operations to increase the size of objects in images as well as decrease them.
我們可以使用形態學運算來增加和減少圖像中對象的大小。
We can also utilize morphological operations to close gaps between objects as well as open them.
我們也可以利用接近空白形態學操作對象之間以及打開它們。
Some of the morphological operations :
一些形態學操作:
Erosion
侵蝕
Dilation
擴張
Opening
開場
Closing
閉幕
Morphological gradient
形態梯度
Black hat
黑帽
Top hat (or “White hat”)
高頂禮帽(或“白帽”)
Sometime, we don’t have to use fancy algorithms to solve computer vision problems. Say few months back i was working on extracting the contents of an invoice The contents inside the structuring element of the invoice
有時,我們不必使用幻想算法來解決計算機視覺問題。 說幾個月前,我正在提取發票的內容發票的結構元素中的內容
You are more likely to find solution using morphological operations.
您更有可能使用形態學運算來找到解決方案。
侵蝕: (Erosion:)
In erosion, the foreground object is eroded to make it smaller as shown in the Fig
在腐蝕中,前景物體被腐蝕以使其變小,如圖所示。
Erosion works by defining a structuring element and then sliding this structuring element from left-to-right and top-to-bottom across the input image.
侵蝕的工作方式是定義一個結構元素,然后在輸入圖像上從左到右和從上到下滑動此結構元素。
A foreground pixel in the input image will be kept only if ALL pixels inside the structuring element are > 0. Otherwise, the pixels are set to 0 (i.e. background).
僅當結構化元素內的所有 像素均大于0時,才會保留輸入圖像中的前景像素。 否則,像素設置為0 (即背景)。
Erosion is useful for removing small blobs in an image or disconnecting two connected objects.
侵蝕對于去除圖像中的小斑點或斷開兩個連接的對象很有用。
#Erosion of text with 2 different iteration
#2次不同迭代的文字侵蝕
import cv2import argparse
導入cv2導入argparse
apr = argparse.ArgumentParser()apr.add_argument(“-i”, “ — image”, required=True, help=”Path to the image”)args = vars(apr.parse_args())
apr = argparse.ArgumentParser()apr.add_argument(“-i”,“ —圖片”,required = True,help =“圖片路徑”)args = vars(apr.parse_args())
image = cv2.imread(args[“image”])
圖片= cv2.imread(args [“ image”])
print(f’(Height,Width,Depth) of the image is: {image.shape}’)
print(圖像的f'(高度,寬度,深度)為:{image.shape}')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)cv2.imshow(“Original”, image)
灰色= cv2.cvtColor(圖片,cv2.COLOR_BGR2GRAY)cv2.imshow(“原始圖片”,圖片)
eroded2 = cv2.erode(gray.copy(), None, iterations=2)cv2.imshow(“Eroded Image with 2 Iteration”, eroded2) eroded4 = cv2.erode(gray.copy(), None, iterations=4)cv2.imshow(“Eroded Image with 4 Iteration”, eroded4)
eroded2 = cv2.erode(gray.copy(),無,迭代次數= 2)cv2.imshow(“腐蝕2次迭代的圖像”,eroded2)eroded4 = cv2.erode(gray.copy(),無,迭代次數= 4) cv2.imshow(“帶有4次迭代的腐蝕圖像”,腐蝕4)
cv2.waitKey(0)
cv2.waitKey(0)
As morphological operations can only be done on grey scale image(black and white) ,however there are exceptions to it .We convert the colored image to a grey scale image by calling cv2.cvtColor function.
由于形態學操作只能在灰度圖像(黑白)上進行,因此有例外。我們通過調用cv2.cvtColor函數將彩色圖像轉換為灰度圖像。
We perform the actual erosion on the next line by making a call to the cv2.erode function. This function takes two required arguments and a third optional one. The first argument is the image that we want to erode — in this case, it’s our binary image. The second argument to cv2.erode is the structuring element. If this value is None , then a structuring element, identical to the 8-neighborhood structuring element we saw above will be used. Of course, you could supply your own custom structuring element here instead of None as well.
我們通過調用cv2.erode函數在下一行執行實際腐蝕。 此函數接受兩個必需的參數和第三個可選的參數。 第一個參數是我們要侵蝕的圖像-在這種情況下,它是我們的二進制圖像。 cv2.erode的第二個參數是結構元素。 如果此值為None,那么將使用與我們在上面看到的8鄰域結構化元素相同的結構化元素。 當然,您可以在此處提供您自己的自定義結構元素,而不是無。
The last argument is the number of iterations the erosion is going to be performed. As the number of iterations increases, we’ll see more and more of the original image characters eaten away.
最后一個參數是腐蝕將要執行的迭代次數。 隨著迭代次數的增加,我們將看到越來越多的原始圖像字符被吞噬。
擴張: (Dilation:)
The opposite of an erosion is a dilation. Just like an erosion will eat away at the foreground pixels, a dilation will grow the foreground pixels.
侵蝕的反面是膨脹 。 就像侵蝕會侵蝕 掉前景像素一樣, 膨脹也會增加前景像素。
Dilations increase the size of foreground object and are especially useful for joining broken parts of an image together.
膨脹會增加前景對象的大小,對于將圖像的損壞部分連接在一起尤其有用。
Dilations, just as an erosion, also utilize structuring elements — a center pixel p of the structuring element is set to white if ANY pixel in the structuring element is > 0.
像侵蝕一樣,膨脹也使用結構元素-如果結構元素中的任何像素> 0 ,則結構元素的中心像素p設置為白色 。
Fig 4.2 DILATION APPLIED TO OUR ORIGINAL IMAGE. AS THE ITERATION INCREASES MORE THE DILATION IS !圖4.2應用于我們原始圖像的稀釋。 隨著迭代次數的增加,距離越來越大!#Dilation of text with 2 different iteration
#使用2個不同的迭代對文本進行膨脹
import cv2import argparse
導入cv2導入argparse
apr = argparse.ArgumentParser()apr.add_argument(“-i”, “ — image”, required=True, help=”Path to the image”)args = vars(apr.parse_args())
apr = argparse.ArgumentParser()apr.add_argument(“-i”,“ —圖片”,required = True,help =“圖片路徑”)args = vars(apr.parse_args())
image = cv2.imread(args[“image”])
圖片= cv2.imread(args [“ image”])
print(f’(Height,Width,Depth) of the image is: {image.shape}’)
print(f'(圖像的高度,寬度,深度)為:{image.shape}')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)cv2.imshow(“Original”, image)
灰色= cv2.cvtColor(圖片,cv2.COLOR_BGR2GRAY)cv2.imshow(“原始圖片”,圖片)
dilated2 = cv2.dilate(gray.copy(), None, iterations=2)cv2.imshow(“Dilated Image with 2 Iteration”, dilated2) dilated4 = cv2.dilate(gray.copy(), None, iterations=4)cv2.imshow(“Dilated Image with 4 Iteration”, dilated4)
dilated2 = cv2.dilate(gray.copy(),無,迭代次數= 2)cv2.imshow(“具有2個迭代的擴張圖像”,dilated2)dilated4 = cv2.dilate(gray.copy(),無,迭代次數= 4) cv2.imshow(“具有4個迭代的放大圖像”,dilated4)
cv2.waitKey(0)
cv2.waitKey(0)
The actual dilation is performed by making a call to the cv2.dilate function, where the actual function signature is identical to that of cv2.erode .
實際的擴展是通過調用cv2.dilate函數執行的,其中實際的函數簽名與cv2.erode的簽名相同。
開場時間: (Opening:)
An opening is an erosion followed by a dilation.
開口是侵蝕,然后是膨脹 。
Performing an opening operation allows us to remove small blobs from an image: first an erosion is applied to remove the small blobs, then a dilation is applied to regrow the size of the original object.
執行打開操作使我們可以從圖像中去除小斑點:首先應用腐蝕以去除小斑點,然后進行膨脹以重新生成原始對象的大小。
Fig 4.3 APPLYING A MORPHOLOGICAL OPENING OPERATION TO OUR INPUT IMAGE.圖4.3將形態學打開操作應用于我們的輸入圖像。#Opening with kernel size of 10,10
#以10,10的內核大小打開
import cv2import argparse
導入cv2導入argparse
apr = argparse.ArgumentParser()apr.add_argument(“-i”, “ — image”, required=True, help=”Path to the image”)args = vars(apr.parse_args())
apr = argparse.ArgumentParser()apr.add_argument(“-i”,“ —圖片”,required = True,help =“指向圖片的路徑”)args = vars(apr.parse_args())
image = cv2.imread(args[“image”])
圖片= cv2.imread(args [“ image”])
print(f’(Height,Width,Depth) of the image is: {image.shape}’)
print(f'(圖像的高度,寬度,深度)為:{image.shape}')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)cv2.imshow(“Original”, image)
灰色= cv2.cvtColor(圖片,cv2.COLOR_BGR2GRAY)cv2.imshow(“原始圖片”,圖片)
kernelSize =(10,10)kernel = cv2.getStructuringElement(cv2.MORPH_RECT, kernelSize)opening = cv2.morphologyEx(gray, cv2.MORPH_OPEN, kernel)cv2.imshow(“Opening Image for kernel size 10,10:”, opening)
kernelSize =(10,10)內核= cv2.getStructuringElement(cv2.MORPH_RECT,kernelSize)打開= cv2.morphologyEx(灰色,cv2.MORPH_OPEN,內核)cv2.imshow(“正在為內核尺寸10,10打開圖像:”,打開)
cv2.waitKey(0)
cv2.waitKey(0)
Here we make a call to cv2.getStructuringElement to build our structuring element. The cv2.getStructuringElement function requires two arguments: the first is the type of structuring element we want, and the second is the size of the structuring element (we have defined our kernel size to be (10,10)).
在這里,我們調用cv2.getStructuringElement來構建結構元素。 cv2.getStructuringElement函數需要兩個參數:第一個是我們想要的結構元素的類型 ,第二個是結構元素的大小 (我們將內核大小定義為(10,10))。
We pass in a value of cv2.MORPH_RECT to indicate that we want a rectangular structuring element. But you could also pass in a value of cv2.MORPH_CROSS to get a cross shape structuring element (a cross is like a 4-neighborhood structuring element, but can be of any size), or cv2.MORPH_ELLIPSE to get a circular structuring element. Exactly which structuring element you use is dependent upon your application — and I’ll leave it as an exercise to the reader to play with each of these structuring elements.
我們傳入一個cv2.MORPH_RECT值來表示我們想要一個矩形結構元素。 但是,您也可以傳入值cv2.MORPH_CROSS以獲取十字形結構元素(十字形類似于4鄰域結構元素,但可以是任意大小),也可以傳入cv2.MORPH_ELLIPSE以獲得圓形結構元素。 確切地說,您使用哪種結構化元素取決于您的應用程序-我將把它留給讀者作為練習使用這些結構化元素的練習。
The actual opening operation is performed on next line by making a call to the cv2.morphologyEx function. This function is abstract in a sense — it allows us to pass in whichever morphological operation we want, followed by our kernel/structuring element. Please try passing other operations and see the difference for yourself.
實際的打開操作是通過調用cv2.morphologyEx函數在下一行執行的。 從某種意義上說,該函數是抽象的-它允許我們傳遞想要的任何形態運算,然后傳遞內核/結構元素。 請嘗試通過其他操作,自己看看有什么不同。
The first required argument of cv2.morphologyEx is the image we want to apply the morphological operation to. The second argument is the actual type of morphological operation — in this case, it’s an opening operation. The last required argument is the kernel/structuring element that we are using.
cv2.morphologyEx的第一個必需參數是我們要對其應用形態學運算的圖像。 第二個參數是形態運算的實際類型 -在這種情況下,它是一個打開運算。 最后一個必需的參數是我們正在使用的內核/結構元素。
Opening allows us to remove small blobs in an image. However, we can also perform other tasks like extracting the Horizontal and vertical lines in an image. We will see more about this in the below final exercise, where we will extract the tabular structure from an invoice using morphological operations.
開口使我們能夠去除圖像中的小斑點 。 但是,我們還可以執行其他任務,例如提取圖像中的水平線和垂直線。 在下面的最終練習中,我們將看到更多相關信息,在該練習中,我們將使用形態學運算從發票中提取表格結構。
閉幕: (Closing:)
The exact opposite to an opening would be a closing. A closing is a dilation followed by an erosion.
與開口完全相反的是閉合 。 結束是擴張之后是侵蝕 。
As the name suggests, a closing is used to close holes inside of objects or for connecting components together.
顧名思義, 閉合用于閉合對象內部的Kong或將組件連接在一起。
Fig 4.4 APPLYING A MORPHOLOGICAL CLOSING OPERATION TO OUR INPUT IMAGE.圖4.4將形態學閉合操作應用于我們的輸入圖像。#Closing with kernel size of 13,13
#以13,13的內核大小關閉
import cv2import argparseimport numpy as np
導入cv2import argparseimport numpy as np
apr = argparse.ArgumentParser()apr.add_argument(“-i”, “ — image”, required=True, help=”Path to the image”)args = vars(apr.parse_args())
apr = argparse.ArgumentParser()apr.add_argument(“-i”,“ —圖片”,required = True,help =“圖片路徑”)args = vars(apr.parse_args())
image = cv2.imread(args[“image”])
圖片= cv2.imread(args [“ image”])
print(f’(Height,Width,Depth) of the image is: {image.shape}’)
print(f'(圖像的高度,寬度,深度)為:{image.shape}')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)cv2.imshow(“Original”, image)
灰色= cv2.cvtColor(圖片,cv2.COLOR_BGR2GRAY)cv2.imshow(“原始圖片”,圖片)
kernelSize =(13,13)kernel = cv2.getStructuringElement(cv2.MORPH_RECT, kernelSize)closing = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, kernel)cv2.imshow(“closing performed with kernel size of 13,13 “, closing)
kernelSize =(13,13)kernel = cv2.getStructuringElement(cv2.MORPH_RECT,kernelSize)關閉= cv2.morphologyEx(灰色,cv2.MORPH_CLOSE,內核)cv2.imshow(“以13,13的內核大小執行關閉,關閉)
cv2.waitKey(0)
cv2.waitKey(0)
形態梯度 (Morphological gradient)
A morphological gradient is the difference between the dilation and erosion. It is useful for determining the outline of a particular object of an image
形態梯度是膨脹和侵蝕之間的差異 。 這對于確定圖像特定對象的輪廓很有用
Fig 4.5 A MORPHOLOGICAL GRADIENT CAN BE USED TO FIND THE OUTLINE OF AN OBJECT IN AN IMAGE.圖4.5可以使用形態學梯度來找到圖像中物體的輪廓。#Morphological gradient applied to extract the boundary of an Image
#應用形態學梯度來提取圖像的邊界
import cv2import argparseimport numpy as np
導入cv2import argparseimport numpy as np
apr = argparse.ArgumentParser()apr.add_argument(“-i”, “ — image”, required=True, help=”Path to the image”)args = vars(apr.parse_args())
apr = argparse.ArgumentParser()apr.add_argument(“-i”,“ —圖片”,required = True,help =“指向圖片的路徑”)args = vars(apr.parse_args())
image = cv2.imread(args[“image”])
圖片= cv2.imread(args [“ image”])
print(f’(Height,Width,Depth) of the image is: {image.shape}’)
print(f'(圖像的高度,寬度,深度)為:{image.shape}')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)cv2.imshow(“Original”, image)
灰色= cv2.cvtColor(圖片,cv2.COLOR_BGR2GRAY)cv2.imshow(“原始圖片”,圖片)
kernelSize =(7,7)
kernelSize =(7,7)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, kernelSize)gradient = cv2.morphologyEx(gray, cv2.MORPH_GRADIENT, kernel)cv2.imshow(“Gradient “, gradient)
內核= cv2.getStructuringElement(cv2.MORPH_RECT,kernelSize)漸變= cv2.morphologyEx(灰色,cv2.MORPH_GRADIENT,內核)cv2.imshow(“漸變”,漸變)
cv2.waitKey(0)
cv2.waitKey(0)
高頂禮帽和黑帽禮帽: (Top Hat & Black Hat:)
A top hat (also known as a white hat) morphological operation is the difference between the original (grayscale/single channel) input image and the opening.
高頂禮帽 (也稱為白帽 )的形態操作是原始(灰度/單通道)輸入圖像與開口 之間的差異 。
A top hat operation is used to reveal bright regions of an image on dark backgrounds. As seen in the Fig the results of Top Hat aren’t very existing. Notice how only regions that are light against a dark background are clearly displayed — in this case, we can clearly see that the license plate region of the car has been revealed.
使用禮帽操作可顯示深色背景上圖像的明亮區域 。 如圖所示,Top Hat的結果并不十分完善。 請注意,只有清晰地顯示了深色背景下的 淺色區域-在這種情況下,我們可以清楚地看到汽車的車牌區域已經露出。
But also note that the license plate characters themselves have not been included. This is because the license plate characters are dark against a light background. And to reveal our license plate characters we’ll need the black hat operator.
但也請注意,車牌字符本身并未包括在內。 這是因為牌照字符在淺色背景下是深色的 。 為了揭示我們的車牌字符,我們需要黑帽操作員。
The black hat operator is simply the opposite of the white hat operator! The results of black hat is a lot more promising as the license plate text itself being darker than the license plate background.
黑帽操作員與白帽操作員完全相反 ! 由于車牌文本本身比車牌背景更暗,黑帽的結果更有希望。
Inference: APPLYING A TOP HAT OPERATION REVEALS LIGHT REGIONS ON A DARK BACKGROUND.
推論 :在黑暗的背景下應用頂級帽子操作可顯示輕區域。
APPLYING THE BLACK HAT OPERATOR REVEALS THE DARK LICENSE PLATE TEXT AGAINST THE LIGHT LICENSE PLATE BACKGROUND.
應用黑帽操作員可將黑暗許可板文本顯示為反對輕許可板背景。
TOP HAT OPERATION REVEALS LIGHT REGIONS ON A DARK BACKGROUND. APPLYING THE 頂部帽子操作可顯示輕區域。 應用黑BLACK HAT OPERATOR REVEALS THE DARK LICENSE PLATE TEXT AGAINST THE LIGHT LICENSE PLATE BACKGROUND.帽操作員可將黑暗許可板文本顯示為反對輕許可板背景。#Top Hat and Black Hat performed on Car number plate
#Top Hat和Black Hat在車號牌上執行
import cv2import argparseimport numpy as np
導入cv2import argparseimport numpy as np
apr = argparse.ArgumentParser()apr.add_argument(“-i”, “ — image”, required=True, help=”Path to the image”)args = vars(apr.parse_args())
apr = argparse.ArgumentParser()apr.add_argument(“-i”,“ —圖片”,required = True,help =“圖片路徑”)args = vars(apr.parse_args())
image = cv2.imread(args[“image”])
圖片= cv2.imread(args [“ image”])
print(f’(Height,Width,Depth) of the image is: {image.shape}’)
print(圖像的f'(高度,寬度,深度)為:{image.shape}')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)cv2.imshow(“Original”, image)
灰色= cv2.cvtColor(圖片,cv2.COLOR_BGR2GRAY)cv2.imshow(“原始圖片”,圖片)
# tophat (also called a “whitehat”) operation will enable s to find light regions on a dark backgroundtophat = cv2.morphologyEx(gray, cv2.MORPH_TOPHAT, rectKernel)
#頂帽(也稱為“白帽”)操作將使s到找到一個黑暗的背景上突= cv2.morphologyEx光區域(灰色,cv2.MORPH_TOPHAT,rectKernel)
rectKernel = cv2.getStructuringElement(cv2.MORPH_RECT, (13, 5))blackhat = cv2.morphologyEx(gray, cv2.MORPH_BLACKHAT, rectKernel) # show the output imagescv2.imshow(“Original”, image)cv2.imshow(“Blackhat”, blackhat)cv2.imshow(“Tophat”, tophat)
rectKernel = cv2.getStructuringElement(cv2.MORPH_RECT,(13,5) ) Blackhat”,blackhat)cv2.imshow(“ Tophat”,tophat)
cv2.waitKey(0)
cv2.waitKey(0)
練習: (Exercise :)
Objective: The objective of this exercise is to extract the tabular region of an invoice document using Morphological operations.
目的 :本練習的目的是使用形態學操作提取發票文件的表格區域。
The invoice document looks like this:
發票文件如下所示:
Fig 4.7 INPUT INVOICE DOCUMENT AS AN IMAGE圖4.7輸入發票文件為圖像# Solution
#解決方案
# import the necessary packagesimport argparseimport cv2import numpy as np # construct the argument parser and parse the argumentsap = argparse.ArgumentParser()ap.add_argument(“-i”, “ — image”, required=True, help=”Path to the image”)args = vars(ap.parse_args()) # load the image and convert it to grayscaleimage = cv2.imread(args[“image”])gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)cv2.imshow(“Original”, image)
#導入必要的軟件包import argparseimport cv2import numpy as np#構造參數解析器并解析參數ap = argparse.ArgumentParser()ap.add_argument(“-i”,“ — image”,required = True,help =”路徑到圖像”)args = vars(ap.parse_args())#加載圖像并將其轉換為灰度圖像= cv2.imread(args [“ image”])gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)cv2。 imshow(“原始圖片”)
kernel = np.ones((3,3),np.uint8)dilation = cv2.dilate(~gray.copy(),kernel,iterations = 1)h_kernel = np.ones((100,1),np.uint8)h_lines = cv2.morphologyEx(dilation, cv2.MORPH_OPEN, h_kernel)v_kernel = np.ones((1,100),np.uint8)v_lines = cv2.morphologyEx(dilation, cv2.MORPH_OPEN, v_kernel)line_img = h_lines + v_linescv2.imshow(“component’, line_img)cv2.waitKey(0)
內核= np.ones((3,3),np.uint8)膨脹= cv2.dilate(?gray.copy(),內核,迭代= 1)h_kernel = np.ones((100,1),np.uint8 )h_lines = cv2.morphologyEx(膨脹,cv2.MORPH_OPEN,h_kernel)v_kernel = np.ones(((1,100),np.uint8)v_lines = cv2.morphologyEx(膨脹,cv2.MORPH_OPEN,v_cnelv)line_img = h_lines + v_lines。 (“ component”,line_img)cv2.waitKey(0)
Result:
結果:
Fig 4.8 DESIRED RESULT OF INVOICE WITH TABULAR STRUCTURE EXTRACTED圖4.8提取了管狀結構的發票的預期結果Here in the above code, the first 11 lines of code are familiar to us. We are loading and converting the image to a gray scale image.
在上面的代碼中,我們很熟悉前11行代碼。 我們正在加載圖像并將其轉換為灰度圖像。
The next two lines are codes are used to dilate the objects in the image. This is done to ensure that there are no broken parts in the objects across the image.
接下來的兩行代碼用于擴展圖像中的對象。 這樣做是為了確保整個圖像的對象中沒有損壞的部分。
Next 4 lines of codes are used to extract all the horizontal lines in the image and all the vertical lines in the image using opening operation with horizontal and vertical kernels respectively. After extracting the horizontal and vertical lines in the image, we connect the lines at the point of intersections and extract the connected components using line_img = h_lines + v_lines resulting in the tabular structure.
接下來的4行代碼分別使用水平和垂直核的打開操作來提取圖像中的所有水平線和圖像中的所有垂直線。 提取圖像中的水平和垂直線后,我們在相交點連接這些線,并使用line_img = h_lines + v_lines提取連接的分量,從而形成表格結構。
However, the line kernels — kernel = np.ones((100,1),np.uint8) that we pass on to the horizontal line detector and vertical line detector is what that makes difference in detecting the lines.
但是,傳遞給水平線檢測器和垂直線檢測器的線核— kernel = np.ones((100,1),np.uint8)才是檢測線的不同之處。
kernel = np.ones((100,1),np.uint8) — Horizontal line kernel
kernel = np.ones(((100,1),np.uint8)—水平線內核
kernel = np.ones((1,100),np.uint8) — Vertical line kernel
kernel = np.ones(((1,100),np.uint8)—垂直線內核
To read the other Lessons from this course, Jump to this article to find the complete syllabus and table of content
要閱讀本課程的其他課程,請跳轉至本文以找到完整的課程提綱和目錄
— — — — — — — — — — -> Click Here
— — — — — — — — — — — —> 單擊此處
翻譯自: https://medium.com/analytics-vidhya/image-basics-using-opencv-lesson-4-of-computer-vision-tutorial-ad5161d1d1ab
計算機視覺課
總結
以上是生活随笔為你收集整理的计算机视觉课_计算机视觉教程—第4课的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用CSS3实现鼠标移到图片上图片放大
- 下一篇: Hive使用入门