https://github.com/potatomexicano/identify_leaf
Identificação de elementos verdes em fotos, usado para detectar folhas/mato em fotos
https://github.com/potatomexicano/identify_leaf
leaf opencv python
Last synced: about 2 months ago
JSON representation
Identificação de elementos verdes em fotos, usado para detectar folhas/mato em fotos
- Host: GitHub
- URL: https://github.com/potatomexicano/identify_leaf
- Owner: PotatoMexicano
- Created: 2022-05-13T14:20:21.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-06-09T14:28:53.000Z (about 4 years ago)
- Last Synced: 2025-04-09T21:43:08.584Z (about 1 year ago)
- Topics: leaf, opencv, python
- Language: Python
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Identify_LEAF
Identificação de elementos verdes em fotos, usado para detectar folhas/mato em fotos

# Código
```python
import cv2
import numpy as np
import os
caminho_imagem = input("Caminho Imagens: ")
for root, _, files in os.walk(caminho_imagem):
for file in files:
if file.endswith(".jpg"):
imagem = os.path.join(root, file)
img = cv2.imread(imagem)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
lower = np.array([27, 0, 20])
upper = np.array([70, 255, 255])
mask = cv2.inRange(hsv, lower, upper)
total_pix = mask.size
number_of_white_pix = np.sum(mask==255)
number_of_black_pix = np.sum(mask==0)
print(f"Brancos | Folhas: {number_of_white_pix}")
print(f"Pretos | Não Folhas: {number_of_black_pix}")
print("Porcentagem folhas: {:.0%}".format((number_of_white_pix/total_pix)))
if (not(os.path.exists(os.path.join(caminho_imagem,'RESULT')))):
os.makedirs(os.path.join(caminho_imagem, 'RESULT'))
store = os.path.join(caminho_imagem, "RESULT",file)
img2 = cv2.merge((mask,mask,mask))
vis = np.concatenate((img, img2), axis=1)
cv2.imwrite(store, vis)
```