Skip to content
Snippets Groups Projects
Commit 48ef135b authored by Zhaoliang Zheng's avatar Zhaoliang Zheng
Browse files

Merge remote-tracking branch 'origin/main' into main

parents bdaec3e0 d915e8cb
Branches
No related merge requests found
Showing
with 15198 additions and 20 deletions
*.pyc
This diff is collapsed.
File added
File added
File added
File added
File added
File added
File added
File added
......@@ -18,7 +18,7 @@ from matplotlib import patches
from detecto import core, utils
from torchvision import transforms
from matplotlib import pyplot as plt
from IPython.display import Image, display, Javascript
# from IPython.display import Image, display, Javascript
distanceDetect = __import__('distance-detection-torch.distance-detection-torch', fromlist = ['distanceDetect']).distanceDetect
print("torch.cuda.is_available() = ", torch.cuda.is_available())
......@@ -26,22 +26,20 @@ print("torch.cuda.is_available() = ", torch.cuda.is_available())
#change the IP address below according to the
#IP shown in the Serial monitor of Arduino code
# url='http://192.168.1.107/cam-lo.jpg'
url='http://192.168.4.1/cam-hi.jpg'
# url='http://192.168.4.1/cam-hi.jpg'
# url='http://192.168.1.107/cam-mid.jpg'
url='http://192.168.0.230/cam-hi.jpg'
#### Modify Detecto Core to include possibility of other base models
def modifyCore():
cModLineNums = [221, 254]
cModLineNums = [221, 253, 254]
cAddLineNums = [254, 256, 257, 258, 259]
# REPLACABLE LINE FOR DIFFERENT LOCAL COMPUTER DEVICES
coreFile = 'C:\\Users\\uclal\\.conda\\envs\\FORAY\\Lib\\site-packages\\detecto\\core.py'
print('debug')
coreFile = 'C:\\Users\\uclal\\.conda\\envs\\foray2\\Lib\\site-packages\\detecto\\core.py'
cModLineVals = [" def __init__(self, classes=None, device=None, pretrained=True, modelname=\'fasterrcnn_resnet50_fpn\'):\n",
" # Load a model pre-trained on COCO - User-Modified",
" self._model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=pretrained)\n"]
cAddLineVals = [" if modelname == \'fasterrcnn_resnet50_fpn\':\n",
" elif modelname == \'fasterrcnn_mobilenet_v3_large_fpn\':\n",
......@@ -146,7 +144,7 @@ def detectLive(model, showSight = True):
#print(frame)
gbx = -1
gby = -1
header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36."}
req = Request(url, headers=header)
img_resp = urlopen(req, timeout=60)
......@@ -265,13 +263,13 @@ distWtsFile = '.\distance-detection-torch\distance-detection-weights-3-2.0sd-202
modelAction = 'load' # 'load' to load previous model, 'new' to train new model (only possible on Colab)
#FOR THE NEXT LINE : UNCOMMENT the first time you run, COMMENT OUT after the first time
#modifyCore()
# modifyCore()
#########
# model = returnModel(modelAction, device, trainLoc, labelSet, modelLoc, modelFile)
# # # ## Testing (using Live Streaming)
# while True:
# detectLive(model)
model = returnModel(modelAction, device, trainLoc, labelSet, modelLoc, modelFile)
# # ## Testing (using Live Streaming)
while True:
detectLive(model)
# ## Testing (using Untrained Images)
# for file in sorted(glob.glob(imageLoc + '/test/*.jpg')):
......
......@@ -11,7 +11,7 @@ def nothing(x):
# detector = apriltag.Detector()
detector = Detector()
def get_AT_6DOF_info(url):
tid,tx,ty,tz= 0,100000,100000,0
......@@ -36,7 +36,8 @@ def get_AT_6DOF_info(url):
fy = 600
cx = 400
cy = 300
AT_size = 0.16
#AT_size = 0.16
AT_size = 0.74
results = detector.detect(gray_image, estimate_tag_pose=True, camera_params=[fx, fy, cx, cy], tag_size=AT_size)
debug_print = 0
for r in results:
......@@ -64,8 +65,8 @@ def get_AT_6DOF_info(url):
tagFamily = r.tag_family.decode("utf-8")
cv2.putText(frame, tagFamily, (ptA[0], ptA[1] - 15), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
cv2.putText(frame, "tx: {:.2f} ty: {:.2f} tz:{:.2f}".format(tx[0], ty[0], tz[0]), (ptA[0], ptA[1] + 30),
......@@ -97,6 +98,11 @@ if __name__ == "__main__":
# url='http://192.168.1.107/cam-hi.jpg'
url='http://192.168.4.1/cam-hi.jpg'
url = 'http://192.168.1.118/cam-hi.jpg'
url = 'http://10.0.0.3/cam-hi.jpg' #03
url = 'http://10.0.0.5/cam-hi.jpg' #01
url = 'http://10.0.0.6/cam-hi.jpg' #02
url = 'http://10.0.0.7/cam-hi.jpg' #06
# cv2.namedWindow("live transmission", cv2.WINDOW_AUTOSIZE)
......
......@@ -121,7 +121,7 @@ void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
//Create the interface that will be used by the camera
openmv::rpc_scratch_buffer<256> scratch_buffer; // All RPC objects share this buffer.
openmv::rpc_i2c_master interface(0x12, 100000); //to make this more robust, consider making address and rate as constructor argument
Camera cam(&interface);
//Camera cam(&interface);
// ========================== Motor part ====================================
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
......@@ -195,7 +195,7 @@ void loop()
int y = 0;
bool goalfind_flag = 0;
goalfind_flag = cam.exe_goalfinder(goal_id[0],goal_id[1],goal_id[2], id, tx, ty, tz, rx, ry, rz);
// goalfind_flag = cam.exe_goalfinder(goal_id[0],goal_id[1],goal_id[2], id, tx, ty, tz, rx, ry, rz);
if (goalfind_flag){
Sent_tx = tx;
Sent_ty = ty;
......
......@@ -70,8 +70,12 @@ pip install opencv-python
conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch
# install pupil-apriltags
pip install pupil-apriltags
# install detecto
pip install detecto==1.2.1
```
## 3 Main_code
There are two files about main code:
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment