mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-27 02:01:40 +00:00
v1 test and bug fixes
This commit is contained in:
@@ -18,11 +18,14 @@ class VisionHandler(metaclass=Singleton):
|
||||
|
||||
def _hsv_threshold(self, hue: list, saturation: list, value: list, img: numpy.ndarray, is_erode: bool,
|
||||
is_dilate: bool):
|
||||
|
||||
img = cv2.erode(img, kernel=self.kernel, iterations=is_erode)
|
||||
img = cv2.dilate(img, kernel=self.kernel, iterations=is_dilate)
|
||||
out = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
|
||||
return cv2.inRange(out, (hue[0], saturation[0], value[0]), (hue[1], saturation[1], value[1]))
|
||||
blur = cv2.blur(img, (3, 3))
|
||||
hsv = cv2.cvtColor(blur, cv2.COLOR_BGR2HSV)
|
||||
lower = numpy.array([hue[0], saturation[0], value[0]])
|
||||
upper = numpy.array([hue[1], saturation[1], value[1]])
|
||||
thresh = cv2.inRange(hsv, lower, upper)
|
||||
erode_img = cv2.erode(thresh, kernel=self.kernel, iterations=is_erode)
|
||||
dilate_img = cv2.dilate(erode_img, kernel=self.kernel, iterations=is_dilate)
|
||||
return dilate_img
|
||||
|
||||
def find_contours(self, binary_img: numpy.ndarray):
|
||||
_, contours, _ = cv2.findContours(binary_img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
|
||||
@@ -122,11 +125,11 @@ class VisionHandler(metaclass=Singleton):
|
||||
intersection_y = (m_a * (intersection_x - x0_a)) + y0_a
|
||||
# finding intersection point
|
||||
if intersection_direction == 'Up':
|
||||
if intersection_y > self.center_y:
|
||||
if intersection_y < self.center_y:
|
||||
return True
|
||||
elif intersection_direction == 'Down':
|
||||
if intersection_y > self.center_y:
|
||||
return False
|
||||
return True
|
||||
elif intersection_direction == 'Left':
|
||||
if intersection_x < self.center_x:
|
||||
return True
|
||||
@@ -139,18 +142,21 @@ class VisionHandler(metaclass=Singleton):
|
||||
f_contour_list = []
|
||||
for index, g_contour in enumerate(i_contours):
|
||||
final_contour = g_contour
|
||||
for c in range(target_group.value):
|
||||
for c in range(target_group.value - 1):
|
||||
try:
|
||||
first_contour = i_contours[index + c]
|
||||
second_contour = i_contours[index + c + 1]
|
||||
except IndexError:
|
||||
continue
|
||||
final_contour = []
|
||||
break
|
||||
if is_intersecting(first_contour, second_contour, intersection_point):
|
||||
final_contour = numpy.concatenate((final_contour, second_contour))
|
||||
else:
|
||||
continue
|
||||
|
||||
f_contour_list.append(final_contour)
|
||||
else:
|
||||
final_contour = []
|
||||
break
|
||||
if final_contour != []:
|
||||
f_contour_list.append(final_contour)
|
||||
|
||||
return f_contour_list
|
||||
else:
|
||||
@@ -188,9 +194,10 @@ class VisionHandler(metaclass=Singleton):
|
||||
continue
|
||||
#checking for contour grouping before sorting
|
||||
grouped_contours = group_target(filtered_contours, TargetGroup[target_grouping], target_intersection)
|
||||
|
||||
sorted_contours = getattr(self.sort_mode, sort_mode)(grouped_contours)
|
||||
|
||||
try:
|
||||
sorted_contours = getattr(self.sort_mode, sort_mode)(grouped_contours)
|
||||
except TypeError:
|
||||
sorted_contours = []
|
||||
return sorted_contours
|
||||
|
||||
@unique
|
||||
@@ -351,7 +358,11 @@ class VisionHandler(metaclass=Singleton):
|
||||
yaw = None
|
||||
valid = False
|
||||
|
||||
res = self.draw_image(input_image=image, contour=final_contour)
|
||||
if curr_pipeline['is_binary']:
|
||||
draw_image = hsv_image
|
||||
else:
|
||||
draw_image = image
|
||||
res = self.draw_image(input_image=draw_image, contour=final_contour)
|
||||
socket.send_pyobj(res)
|
||||
socket.send_json(dict(
|
||||
pitch=pitch,
|
||||
|
||||
1
backend/settings/cams/AN-VC500 Camera.json
Normal file
1
backend/settings/cams/AN-VC500 Camera.json
Normal file
@@ -0,0 +1 @@
|
||||
{"pipelines": {"pipeline0": {"exposure": 4, "brightness": 74, "orientation": "Normal", "resolution": [320, 160], "hue": [43, 80], "saturation": [159, 255], "value": [55, 255], "erode": false, "dilate": false, "area": [0, 100], "ratio": [0, 89.9], "extent": [61, 100], "is_binary": 0, "sort_mode": "Largest", "target_group": "Dual", "target_intersection": "Up"}}, "path": "/dev/v4l/by-path/pci-0000:02:03.0-usb-0:1:1.0-video-index0", "video_mode": {"fps": 30, "width": 640, "height": 480, "pixel_format": "kYUYV"}}
|
||||
@@ -1 +1 @@
|
||||
{"team_number": 1577, "connection_type": "DHCP", "ip": "", "gateway": "", "hostname": "Chameleon-Vision", "curr_camera": "USB Camera-B4.09.24.1", "curr_pipeline": "pipeline0"}
|
||||
{"team_number": 1577, "connection_type": "DHCP", "ip": "", "gateway": "", "hostname": "Chameleon-Vision", "curr_camera": "AN-VC500 Camera", "curr_pipeline": "pipeline0"}
|
||||
@@ -1,8 +1,8 @@
|
||||
<template>
|
||||
<div id="Threshold">
|
||||
<chrange class="spacing" title="Hue" Xkey="hue"></chrange>
|
||||
<chrange class="spacing" title="Saturation" Xkey="saturation"></chrange>
|
||||
<chrange class="spacing" title="Value" Xkey="value"></chrange>
|
||||
<chrange class="spacing" title="Hue" Xkey="hue" :maximum="180"></chrange>
|
||||
<chrange class="spacing" title="Saturation" Xkey="saturation" :maximum="255"></chrange>
|
||||
<chrange class="spacing" title="Value" Xkey="value" :maximum="255"></chrange>
|
||||
<chswitch class="spacing" title="Erode" Xkey="erode"></chswitch>
|
||||
<chswitch class="spacing" title="Dilate" Xkey="dilate"></chswitch>
|
||||
</div>
|
||||
|
||||
@@ -64,10 +64,10 @@
|
||||
},
|
||||
isBinary: {
|
||||
get: function(){
|
||||
return this.$store.state.isBinaryImage;
|
||||
return this.$store.state.is_binary;
|
||||
},
|
||||
set: function(value){
|
||||
this.$store.commit('isBinaryImage',value)
|
||||
this.$store.commit('is_binary',value)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
<InputNumber style="align-self: flex-start;" v-model="value[0]" size="small" :step="steps" ></InputNumber>
|
||||
</Col>
|
||||
<Col span="10">
|
||||
<Slider range v-model="value" @on-input="handleInput" :step="steps"></Slider>
|
||||
<Slider range v-model="value" @on-input="handleInput" :step="steps" :max="maximum"></Slider>
|
||||
</Col>
|
||||
<Col span="4" style="text-align: right">
|
||||
<InputNumber style="align-self: flex-end;" v-model="value[1]" size="small" :step="steps"></InputNumber>
|
||||
<InputNumber style="align-self: flex-end;" v-model="value[1]" size="small" :step="steps" :max="maximum"></InputNumber>
|
||||
</Col>
|
||||
</row>
|
||||
</template>
|
||||
@@ -22,7 +22,8 @@
|
||||
props:{
|
||||
title:String,
|
||||
Xkey:String,
|
||||
steps:Number
|
||||
steps:Number,
|
||||
maximum:Number
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
||||
@@ -40,7 +40,7 @@ export const store = new Vuex.Store({
|
||||
hostName:"",
|
||||
//live info
|
||||
streamAdress:("http://"+location.hostname + ":1181/stream.mjpg"),
|
||||
isBinaryImage:0,
|
||||
is_binary:0,
|
||||
//camera lists
|
||||
|
||||
},
|
||||
@@ -68,7 +68,7 @@ export const store = new Vuex.Store({
|
||||
gateWay : set('gateway'),
|
||||
hostName : set('hostname'),
|
||||
streamAdress : set('streamAdress'),
|
||||
isBinaryImage: set('isBinaryImage'),
|
||||
is_binary: set('is_binary'),
|
||||
cameraList : set('cameraList'),
|
||||
pipelineList: set('piplineList'),
|
||||
sort_mode: set('sort_mode'),
|
||||
@@ -96,7 +96,7 @@ export const store = new Vuex.Store({
|
||||
gateWay: state => state.gateWay,
|
||||
hostName: state => state.hostName,
|
||||
streamAdress: state => state.streamAdress,
|
||||
isBinaryImage: state => state.isBinaryImage,
|
||||
is_binary: state => state.is_binary,
|
||||
cameraList: state => state.cameraList,
|
||||
pipelineList: state => state.pipelineList,
|
||||
sort_mode: state => state.sort_mode,
|
||||
|
||||
Reference in New Issue
Block a user