# Hello World Example
#
# Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script!
import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(10)
sensor.set_auto_whitebal(False) # Create a clock object to track the FPS.
ROI=(80,30,15,15)
Red = [56, 70, 39, 80, 41, 67]
yellow = [90, 100, -23, -10, 31, 70]
green=[71, 90, -71, -32, 6, 46]
while(True):
img = sensor.snapshot() # Take a picture and return the image.
blobs = img.find_blobs([Red])
for blob in blobs:
print(blob.cx(), blob.cy())
img.draw_circle(blob.cx(), blob.cy(), 10)
img.draw_string(blob.cx(), blob.cy(), "Red")
blobs = img.find_blobs([yellow])
for blob in blobs:
print(blob.cx(), blob.cy())
img.draw_circle(blob.cx(), blob.cy(), 10)
img.draw_string(blob.cx(), blob.cy(), "yellow")
blobs = img.find_blobs([green])
for blob in blobs:
print(blob.cx(), blob.cy())
img.draw_circle(blob.cx(), blob.cy(), 10)
img.draw_string(blob.cx(), blob.cy(), "green")
import sensor, image, time
# 센서 초기화
sensor.reset()
# 픽셀 형식을 RGB565로 설정
sensor.set_pixformat(sensor.RGB565)
# 프레임 크기를 QVGA로 설정
sensor.set_framesize(sensor.QVGA)
# 프레임 건너뛰기 (초기 설정)
sensor.skip_frames(10)
# 자동 화이트 밸런스 비활성화
sensor.set_auto_whitebal(False)
# 관심 영역 설정
ROI = (80, 30, 15, 15)
# 색상 범위 설정
Red = [56, 70, 39, 80, 41, 67]
Yellow = [90, 100, -23, -10, 31, 70]
Green = [71, 90, -71, -32, 6, 46]
while(True):
# 이미지 캡처
img = sensor.snapshot()
# 빨간색 블롭 찾기
blobs = img.find_blobs([Red])
for blob in blobs:
print(blob.cx(), blob.cy()) # 블롭의 중심 좌표 출력
img.draw_circle(blob.cx(), blob.cy(), 10) # 블롭 중심에 원 그리기
img.draw_string(blob.cx(), blob.cy(), "Red") # 블롭에 "Red" 문자열 표시
# 노란색 블롭 찾기
blobs = img.find_blobs([Yellow])
for blob in blobs:
print(blob.cx(), blob.cy())
img.draw_circle(blob.cx(), blob.cy(), 10)
img.draw_string(blob.cx(), blob.cy(), "Yellow")
# 녹색 블롭 찾기
blobs = img.find_blobs([Green])
for blob in blobs:
print(blob.cx(), blob.cy())
img.draw_circle(blob.cx(), blob.cy(), 10)
img.draw_string(blob.cx(), blob.cy(), "Green")
#이 프로그램은 센서를 초기화하고, RGB565 형식으로 이미지를 캡처하여 빨간색, 노란색, 녹색 블롭(작은 덩어리)을 감지합니다. 각 블롭의 중심 좌표를 출력하고 이미지에 원과 문자열을 그려 표시합니다. 도움이 되었길 바라요!
import sensor, image, time
# 센서 초기화
sensor.reset()
# 픽셀 형식을 RGB565로 설정
sensor.set_pixformat(sensor.RGB565)
# 프레임 크기를 QVGA로 설정
sensor.set_framesize(sensor.QVGA)
# 프레임 건너뛰기 (초기 설정)
sensor.skip_frames(10)
# 자동 화이트 밸런스 비활성화
sensor.set_auto_whitebal(False)
# 관심 영역 설정
ROI = (80, 30, 15, 15)
# 색상 범위 설정
Red = [56, 70, 39, 80, 41, 67]
Yellow = [90, 100, -23, -10, 31, 70]
Green = [71, 90, -71, -32, 6, 46]
Blue = [18, 38, -12, 10, -63, -23]
Purple = [30, 60, 12, 38, -65, -23]
Black = [0, 20, -128, 127, -128, 127]
Navy = [0, 30, -30, 0, -50, -10]
Pink = [40, 70, 20, 60, 0, 30]
while(True):
# 이미지 캡처
img = sensor.snapshot()
# 빨간색 블롭 찾기
blobs = img.find_blobs([Red])
for blob in blobs:
print(blob.cx(), blob.cy()) # 블롭의 중심 좌표 출력
img.draw_circle(blob.cx(), blob.cy(), 10) # 블롭 중심에 원 그리기
img.draw_string(blob.cx(), blob.cy(), "Red") # 블롭에 "Red" 문자열 표시
# 노란색 블롭 찾기
blobs = img.find_blobs([Yellow])
for blob in blobs:
print(blob.cx(), blob.cy())
img.draw_circle(blob.cx(), blob.cy(), 10)
img.draw_string(blob.cx(), blob.cy(), "Yellow")
# 녹색 블롭 찾기
blobs = img.find_blobs([Green])
for blob in blobs:
print(blob.cx(), blob.cy())
img.draw_circle(blob.cx(), blob.cy(), 10)
img.draw_string(blob.cx(), blob.cy(), "Green")
# 청색 블롭 찾기
blobs = img.find_blobs([Blue])
for blob in blobs:
print(blob.cx(), blob.cy())
img.draw_circle(blob.cx(), blob.cy(), 10)
img.draw_string(blob.cx(), blob.cy(), "Blue")
# 자주색 블롭 찾기
blobs = img.find_blobs([Purple])
for blob in blobs:
print(blob.cx(), blob.cy())
img.draw_circle(blob.cx(), blob.cy(), 10)
img.draw_string(blob.cx(), blob.cy(), "Purple")
# 검정색 블롭 찾기
blobs = img.find_blobs([Black])
for blob in blobs:
print(blob.cx(), blob.cy())
img.draw_circle(blob.cx(), blob.cy(), 10)
img.draw_string(blob.cx(), blob.cy(), "Black")
# 남색 블롭 찾기
blobs = img.find_blobs([Navy])
for blob in blobs:
print(blob.cx(), blob.cy())
img.draw_circle(blob.cx(), blob.cy(), 10)
img.draw_string(blob.cx(), blob.cy(), "Navy")
# 분홍색 블롭 찾기
blobs = img.find_blobs([Pink])
for blob in blobs:
print(blob.cx(), blob.cy())
img.draw_circle(blob.cx(), blob.cy(), 10)
img.draw_string(blob.cx(), blob.cy(), "Pink")