Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Get position #53

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
20316f8
add camera
KANBE8810 Nov 5, 2021
6f178f5
change camera model
RikuYokoo Nov 7, 2021
cf5afc6
add camera controller
RikuYokoo Nov 7, 2021
ab9d804
保存機能の追加
KANBE8810 Nov 9, 2021
930036b
一時保存
KANBE8810 Dec 4, 2021
8548294
add super visor
RikuYokoo Dec 23, 2021
1dcb5b7
get the ball coordinates from the supervisor
RikuYokoo Dec 24, 2021
8e189ba
add get_position
yasuohayashibara Dec 26, 2021
01d81a8
get position
yasuohayashibara Dec 26, 2021
ce3a0fd
Merge branch 'pose_capture_test' into get_position
KANBE8810 Jan 2, 2022
984f9cf
ロボットの位置調整・カメラ追加
KANBE8810 Jan 3, 2022
0f71322
シュートコースのランダム化
KANBE8810 Jan 11, 2022
929ee8f
Obtain 3D coordinates to keypoints
KANBE8810 Apr 15, 2022
8ce8367
周期を揃えた
KANBE8810 Apr 25, 2022
cdd8bb1
Merge branch 'main' into get_position
KANBE8810 Apr 25, 2022
71b8981
Migrate annotation_keypoints to get_position
KANBE8810 May 18, 2022
0d3a9ed
annotation_keypointsを一部取り込み
KANBE8810 May 30, 2022
5efb5d9
2次元キーポイントが取得できるように対応
KANBE8810 Aug 18, 2022
7b25ef3
座標変換の追加,シュートコースの変更
KANBE8810 Aug 22, 2022
6f8b8b0
ボールの座標取得を追加
KANBE8810 Aug 25, 2022
5ca4478
キッカーのみに変更
KANBE8810 Aug 29, 2022
36ade05
座標取るタイミングを変更
KANBE8810 Aug 29, 2022
93129a0
斜めのキックができるように変更
KANBE8810 Sep 5, 2022
e527320
ワールドファイルの修正
KANBE8810 Sep 5, 2022
d605f2f
ファイル整理
KANBE8810 Nov 10, 2022
1b2fe80
15度-15度を追加
KANBE8810 Nov 26, 2022
229d976
add
KANBE8810 Nov 26, 2022
955e662
a
KANBE8810 Nov 28, 2022
a0330f0
fix
KANBE8810 Dec 5, 2022
c0ebddf
fix
KANBE8810 Dec 5, 2022
42f4cf9
bag fix
KANBE8810 Dec 6, 2022
d61bab4
add new world
KANBE8810 Dec 6, 2022
02890d0
fix
HirokiHasegawa777 Jan 9, 2023
6005248
add cross kick
HirokiHasegawa777 Feb 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 90 additions & 42 deletions controllers/annotation_keypoints/annotation_keypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@
deviceImagePath = os.getcwd()
#robot = Robot()
supervisor = Supervisor()
timestep = int(supervisor.getBasicTimeStep()*10)
timestep = int(supervisor.getBasicTimeStep())
camera = supervisor.getDevice('camera_sensor')
camera.enable(timestep)
camera.recognitionEnable(timestep)
camera.enableRecognitionSegmentation()
number = 0

print("hasRecognition(): " + str(camera.hasRecognition()))
print("hasRecognitionSegmentation(): " + str(camera.hasRecognitionSegmentation()))
#print("hasRecognition(): " + str(camera.hasRecognition()))
#print("hasRecognitionSegmentation(): " + str(camera.hasRecognitionSegmentation()))

cv2.startWindowThread()
cv2.namedWindow("preview")
#cv2.startWindowThread()
#cv2.namedWindow("preview")

color_dict = { \
"ball_color" :(0.0, 0.0, 1.0), \
#"ball_color" :(0.0, 0.0, 1.0), \
"colorHead" :(1.0, 1.0, 1.0), \
"colorNeck" :(0.5, 0.5, 0.5), \
"colorShoulderL":(0.0, 0.5, 0.0), \
"colorShoulderR":(0.5, 0.0, 0.0), \
"colorElbowL" :(0.0, 0.6, 0.0), \
"colorElbowR" :(0.6, 0.0, 0.0), \
"colorWristL" :(0.0, 0.7, 0.0), \
# "colorNeck" :(0.5, 0.5, 0.5), \
"colorShoulderL":(0.0, 0.499, 0.0), \
"colorShoulderR":(0.0, 0.0, 0.499), \
"colorElbowL" :(0.0, 0.599, 0.0), \
"colorElbowR" :(0.599, 0.0, 0.0), \
"colorWristL" :(0.0, 0.0, 1.0), \
"colorWristR" :(0.7, 0.0, 0.0), \
"colorHipL" :(0.0, 0.8, 0.0), \
"colorHipR" :(0.8, 0.0, 0.0), \
Expand All @@ -40,48 +40,96 @@
"colorAnkleL" :(0.0, 1.0, 0.0), \
"colorAnkleR" :(1.0, 0.0, 0.0) \
}
pos_dict = dict()
#pos_dict = dict()
lines = [
["colorHead" , "colorNeck" ],
["colorNeck" , "colorShoulderL"],
["colorShoulderL", "colorElbowL" ],
["colorElbowL" , "colorWristL" ],
["colorNeck" , "colorShoulderR"],
["colorShoulderR", "colorElbowR" ],
["colorElbowR" , "colorWristR" ],
["colorNeck" , "colorHipL" ],
["colorHipL" , "colorKneeL" ],
["colorKneeL" , "colorAnkleL" ],
["colorNeck" , "colorHipR" ],
["colorHipR" , "colorKneeR" ],
["colorKneeR" , "colorAnkleR" ]
["colorHead" , "colorNeck" ],
["colorNeck" , "colorShoulderL"],
["colorShoulderL", "colorElbowL" ],
["colorElbowL" , "colorWristL" ],
["colorNeck" , "colorShoulderR"],
["colorShoulderR", "colorElbowR" ],
["colorElbowR" , "colorWristR" ],
["colorNeck" , "colorHipL" ],
["colorHipL" , "colorKneeL" ],
["colorKneeL" , "colorAnkleL" ],
["colorNeck" , "colorHipR" ],
["colorHipR" , "colorKneeR" ],
["colorKneeR" , "colorAnkleR" ]
]


memomemo_x = 0
memomemo_y = 0
memo_x = 0
memo_y = 0
cnt_2 = -1

while supervisor.step(timestep) != -1:
supervisor.getFromDef('BALL').getField('translation').setSFVec3f([random.uniform(0.0, 4.0), random.uniform(-1.0, 1.0), 0.1])
supervisor.getFromDef('ENEMY1').getField('rotation').setSFRotation([0, 0, 1, random.uniform(-1.0, 1.0)+3.14])
for i in range(10):
supervisor.step(timestep)
camera.saveImage(deviceImagePath + '/images/image' + str(number) + '.jpg', 80)
camera.saveRecognitionSegmentationImage(deviceImagePath + '/images/segmentation_image' + str(number) + '.jpg', 80)
# supervisor.getFromDef('BALL').getField('translation').setSFVec3f([random.uniform(0.0, 4.0), random.uniform(-1.0, 1.0), 0.1])
# supervisor.getFromDef('ENEMY1').getField('rotation').setSFRotation([0, 0, 1, random.uniform(-1.0, 1.0)+3.14])
# for i in range(10):
# supervisor.step(timestep)
camera.saveImage(deviceImagePath + '/images_new/image' + str(number) + '.jpg', 80)
#camera.saveRecognitionSegmentationImage(deviceImagePath + '/images/segmentation_image' + str(number) + '.jpg', 80)
number += 1
seg_img = camera.getRecognitionSegmentationImage()
img = np.frombuffer(seg_img, np.uint8).reshape((camera.getHeight(), camera.getWidth(), 4))

cnt = -1
file_path_2d = 'txt_2d_use/image' + str(cnt_2) + '.txt'
file_path_3d = 'image_txt.txt'


for key, val in color_dict.items():
cnt +=1
cnt_2 +=1
color = (val[0]*255, val[1]*255, val[2]*255, 255)
area = cv2.inRange(img, color, color)
x, y, width, height = cv2.boundingRect(area)
x, y, w, h = cv2.boundingRect(area)
#cv2.rectangle(img, (x, y), (x + width, y + height), color=color, thickness=2)
pos_dict[key] = (x + width / 2, y + height / 2)
print(key + ": " + str(x) + ", y: " + str(y) + ", with: " + str(width) + ", height: " + str(height))
#pos_dict[key] = (x + width / 2, y + height / 2)
#print(key + ": " + str(x) + ", y: " + str(y) + ", with: " + str(width) + ", height: " + str(height))
#print(key + ": " + str(x) + ", y: " + str(y))
x = x + (w-1)/2
y = y + (h-1)/2
if x == -0.5 and y == -0.5:
x = memomemo_x
y = memomemo_y
y += 20

with open(file_path_2d, 'a') as f:
f.write("%s" % int(x))
f.write(',')
f.write("%s" % int(y))
# if int(x)!=0 or int(y)!=0:
f.write(',2\n')

with open(file_path_3d, 'a') as f:
f.write("%s" % int(x))
f.write(',')
f.write("%s" % int(y))
if cnt < 12:
f.write(',')
else:
f.write('\n')

# if int(x)!=0 or int(y)!=0:
# else:
# f.write(',0\n')
memomemo_x = memo_x
memomemo_y = memo_y
memo_x = x
memo_y = y
# if cnt >= 600:
# print("anno_finish\n")
# sys.exit()

for line in lines:
x0, y0 = int(pos_dict[line[0]][0]), int(pos_dict[line[0]][1])
x1, y1 = int(pos_dict[line[1]][0]), int(pos_dict[line[1]][1])
print("x0: "+str(x0)+", y0: "+str(y0)+", x1: "+str(x1)+", y1: "+str(y1)+"\r\n")
cv2.line(img, (x0, y0), (x1, y1), color=(255, 255, 255, 255), thickness=2)
# for line in lines:
# x0, y0 = int(pos_dict[line[0]][0]), int(pos_dict[line[0]][1])
# x1, y1 = int(pos_dict[line[1]][0]), int(pos_dict[line[1]][1])
# print("x0: "+str(x0)+", y0: "+str(y0)+", x1: "+str(x1)+", y1: "+str(y1)+"\r\n")
# cv2.line(img, (x0, y0), (x1, y1), color=(255, 255, 255, 255), thickness=2)

cv2.imshow("preview", img)
cv2.waitKey(timestep)
# cv2.imshow("preview", img)
# cv2.waitKey(timestep)

68 changes: 68 additions & 0 deletions controllers/get_position/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"files.associations": {
"iomanip": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"array": "cpp",
"atomic": "cpp",
"hash_map": "cpp",
"hash_set": "cpp",
"strstream": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"codecvt": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"filesystem": "cpp",
"functional": "cpp",
"iterator": "cpp",
"map": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"set": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp"
}
}
Loading