Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import numpy as np
  2. import cv2
  3. import matplotlib.pyplot as plt
  4.  
  5. %matplotlib inline
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12. img = cv2.imread('C:/Users/Sergey/Sanya/komputernoe_zrenie/CV_SOS-master/less_03/bin_ship/task_img/test_image_00.jpg')
  13. img_plt = cv2.cvtColor(img.copy(), cv2.COLOR_BGR2GRAY)
  14.  
  15. ret,thresh1 = cv2.threshold(img_plt,88,255,cv2.THRESH_BINARY)
  16. titles = ['Original Image','BINARY']
  17. images = [img_plt, thresh1]
  18. plt.figure(figsize=(20,20))
  19. for i in range(2):
  20. plt.subplot(2,3,i+1),plt.imshow(images[i],'gray')
  21. plt.title(titles[i])
  22. plt.xticks([]),plt.yticks([])
  23.  
  24.  
  25.  
  26. thresh1.shape = (thresh1.shape[0]*256, 3)
  27. s = 0
  28. a = np.array(([[255, 255, 255]]))
  29.  
  30.  
  31. for i in range(thresh1.shape[0]):
  32. if (thresh1[i] == a).all():
  33. s += 1
  34.  
  35. plt.show()
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. print("Площадь корабля = ",s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement