Halcon 通過灰度識別顏色

上結果:
在這裏插入圖片描述
看原圖:
在這裏插入圖片描述
看代碼:

dev_close_window ()
dev_open_window (0, 0, 800, 600, 'black', WH)
read_image (Image, 'D:/HalconWorkplace/img/color.png')
rgb1_to_gray (Image, Gray)
*黑色
threshold (Gray, Regions, 0, 10)
*紅色
threshold (Gray, Regions1, 20, 100)
*綠色
threshold (Gray, Regions2, 149, 154)
*藍色
threshold (Gray, Regions3, 120, 139)
*黃色
threshold (Gray, Regions4, 155, 238)

connection (Regions, ConnectedRegions)
connection (Regions1, ConnectedRegions1)
connection (Regions2, ConnectedRegions2)
connection (Regions3, ConnectedRegions3)
connection (Regions4, ConnectedRegions4)

dev_clear_window()
dev_display(Image)
dev_set_color('black')

area_center (ConnectedRegions, Area, Row, Column)
set_tposition (WH, Row[0]-100, Column[0]-15)
write_string (WH, '黑色')

dev_set_color('red')
area_center (ConnectedRegions1, Area, Row, Column)
set_tposition (WH, Row[0]-100, Column[0]-15)
write_string (WH, '紅色')

dev_set_color('green')
area_center (ConnectedRegions2, Area, Row, Column)
set_tposition (WH, Row[0]-100, Column[0]-15)
write_string (WH, '綠色')

dev_set_color('blue')
area_center (ConnectedRegions3, Area, Row, Column)
set_tposition (WH, Row[0]-100, Column[0]-15)
write_string (WH, '藍色')

dev_set_color('yellow')
area_center (ConnectedRegions4, Area, Row, Column)
set_tposition (WH, Row[0]-100, Column[0]-15)
write_string (WH, '黃色')
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章