From b59748b5003dc67c8a2d9155d95eaeae275e9c9e Mon Sep 17 00:00:00 2001 From: Zilian <13718722639leo@gmail.com> Date: Tue, 16 Nov 2021 21:00:37 +0100 Subject: [PATCH] add main --- README.md | 2 +- src/detect.py | 4 ++-- src/location.py | 1 + src/main.py | 30 +++++++++++++++--------------- src/move.py | 5 +++-- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 832fb08..c70a027 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ The software has three main modules: We also provide `main.py` as a warpper for all the modules above. By runing it, you can make Farmbot automatically conduct the whole process. The three modules can also be run sperately, mostly for debugging purpose. -First go to `/src/` to run the following scripts. +First go to `/src/` and `conda activate <env>` to run the following scripts. `<env>` is the same as the one you created in *Install, Compile* ### Move Famrbot, take photos, and open/close the gripper ### YOLO detection All the arguments for file path are set to default. diff --git a/src/detect.py b/src/detect.py index 28f2fe8..acccc62 100644 --- a/src/detect.py +++ b/src/detect.py @@ -120,7 +120,7 @@ def save_annotations(original_size, name, image, detections, class_names): f.write("{} {:.4f} {:.4f} {:.4f} {:.4f} {:.4f}\n".format(label, x*width, y*height, w*width, h*height, float(confidence))) -def main(): +def detect(): args = parser() check_arguments_errors(args) @@ -160,4 +160,4 @@ def main(): if __name__ == "__main__": - main() + detect() diff --git a/src/location.py b/src/location.py index 864ca95..69a8b16 100644 --- a/src/location.py +++ b/src/location.py @@ -254,6 +254,7 @@ if __name__ == '__main__': parser.add_argument('-v', '--verbose', action='store_true', help='Verbose mode') arguments = parser.parse_args() + if arguments.verbose: basicConfig(filename=arguments.log, level=DEBUG) else: diff --git a/src/main.py b/src/main.py index c4d9b16..ba5dc8a 100644 --- a/src/main.py +++ b/src/main.py @@ -17,30 +17,30 @@ from location import * _Log = getLogger(__name__) -def remove_overlap(): - return +def remove_overlap(table_coordinate:DataFrame, tolerance=50.00)->DataFrame: + ''' + compare every two coordinates, if their Euclidean distance is smaller than tolerance + , delete the one with lower probability + ''' + # 这又要求重写前面的了,加入 probability + return table_coordinate # 还要定期清理掉img下所有文件 def remove_temp(): return -def choose_class(category: int) -> : - ''' - Choose the category to pick up - ''' - return - def main(args: Namespace): # scan - + scan() # detect - + detect() # calculate locations - + list_global_coordinate = cal_location() # choose class - list_global_coordinate[:, 0] - + table_global_coordinate = DataFrame(list_global_coordinate, columns=['class', 'x', 'y']) + goal_class = list_global_coordinate[table_global_coordinate['class']==args.category] + # 添加一个if判断,如果该类为空,则显示 # remove overlap # move @@ -79,8 +79,8 @@ if __name__ == '__main__': ) # arguemtns for grip parser.add_argument( - '-cl', - '--class', + '-ca', + '--category', type=str, help='Choose the class of fruits to be picked up. There are tomato, mushroom,\ potato, carrot, beetroot, zucchini, hand' diff --git a/src/move.py b/src/move.py index 5f380fa..32efa82 100644 --- a/src/move.py +++ b/src/move.py @@ -39,10 +39,11 @@ class Opts: self.flag = flag -def scan(min_x=0, max_x=1300, min_y=0, max_y=1000, delta=500, offset=0, flag=True) -> List: +def scan(min_x=0, max_x=1300, min_y=0, max_y=1000, delta=500, offset=0, flag=True) -> List: #里面的数字需要重新测量 ''' scan the bed at a certain height, first move along x axis, then y, like a zig zag; Taking pictures and record the location of the camera that corresponds to the picture + The default value of x, y should be from the measurement of Farmbot Input: min_x: left most point on x axis max_x: right most point on x axis min_y: front most point on y axis @@ -77,7 +78,7 @@ def scan(min_x=0, max_x=1300, min_y=0, max_y=1000, delta=500, offset=0, flag=Tru #client #需要添加一个函数,读取当前位置,需要吗? client.take_photo() # 拍照时,需要记住每张照片对应的相机位置! client.shutdown() - return pts + return pts # 这里应该写入文件 img/location def download_images() -> Path: -- GitLab