Initial commit
This commit is contained in:
87
lab6_1/lab6_1.py
Normal file
87
lab6_1/lab6_1.py
Normal file
@@ -0,0 +1,87 @@
|
||||
import os
|
||||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
def main():
|
||||
lstone=list()
|
||||
lsttwo=list()
|
||||
image1 = cv2.imread("D:\\MACH\\MACH\\LAB_2\\image0.jpg")
|
||||
image2=image1
|
||||
image3=image1
|
||||
image4=image1
|
||||
image5=image1
|
||||
image6=image1
|
||||
image7=image1
|
||||
image2=erode_cv(image2,11)
|
||||
image3=dilate_cv(image3,11)
|
||||
image4=median_cv(image4,5)
|
||||
image5=erode_ipp(image5,14)
|
||||
image6=dilate_ipp(image6,14)
|
||||
image7=median_ipp(image7,7)
|
||||
|
||||
cv2.imshow("Image_load",image1)
|
||||
cv2.imshow("erode_cv",image2)
|
||||
cv2.imshow("dilate_cv",image3)
|
||||
cv2.imshow("median_cv",image4)
|
||||
cv2.imshow("erode_ipp",image5)
|
||||
cv2.imshow("dilate_ipp",image6)
|
||||
cv2.imshow("median_ipp",image7)
|
||||
cv2.waitKey(0)
|
||||
|
||||
lstone=sravit_metod(image2)
|
||||
lsttwo=sravit_metod(image5)
|
||||
lsttree=lsttwo[len(lstone):]
|
||||
print("Erode")
|
||||
print("Количество отличий : "+str(len(lsttwo)-len(lstone))+" \nРазница")
|
||||
print(lsttree)
|
||||
|
||||
lstone=sravit_metod(image3)
|
||||
lsttwo=sravit_metod(image5)
|
||||
lsttree=lstone[len(lsttwo):]
|
||||
print("Dilate")
|
||||
print("Количество отличий : "+str(len(lstone)-len(lsttwo))+" \nРазница")
|
||||
print(lsttree)
|
||||
|
||||
lstone=sravit_metod(image4)
|
||||
lsttwo=sravit_metod(image7)
|
||||
lsttree=lstone[len(lsttwo):]
|
||||
print("Median")
|
||||
print("Количество отличий : "+str(len(lstone)-len(lsttwo))+" \nРазница")
|
||||
print(lsttree)
|
||||
|
||||
def erode_cv(s1,s2):
|
||||
s1 = cv2.erode(s1, np.ones((s2, s2)))
|
||||
return s1
|
||||
def dilate_cv(s1,s2):
|
||||
s1 = cv2.dilate(s1, np.ones((s2, s2)))
|
||||
return s1
|
||||
def median_cv(s1,s2):
|
||||
s1 = cv2.medianBlur(s1,s2)
|
||||
return s1
|
||||
def erode_ipp(s1,s2):
|
||||
s1 = cv2.erode(s1, np.ones((s2, s2)))
|
||||
return s1
|
||||
def dilate_ipp(s1,s2):
|
||||
s1 = cv2.dilate(s1, np.ones((s2, s2)))
|
||||
return s1
|
||||
def median_ipp(s1,s2):
|
||||
s1 = cv2.medianBlur(s1,s2)
|
||||
return s1
|
||||
|
||||
def sravit_metod(s1):
|
||||
cv2.imwrite("im1.jpg",s1)
|
||||
s1 = cv2.imread("im1.jpg", 0)
|
||||
th, threshed = cv2.threshold(s1, 100, 255,cv2.THRESH_BINARY_INV|cv2.THRESH_OTSU)
|
||||
cnts = cv2.findContours(threshed, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)[-2]
|
||||
t1= 3
|
||||
t2 = 20
|
||||
xcnts = []
|
||||
for cnt in cnts:
|
||||
if t1<cv2.contourArea(cnt) <t2:
|
||||
xcnts.append(cnt)
|
||||
os.remove("im1.jpg")
|
||||
return xcnts
|
||||
|
||||
if __name__=="__main__":
|
||||
main()
|
Reference in New Issue
Block a user