Skip to content

Commit 3bcc2a6

Browse files
committed
add 2 cameras support
1 parent 12c1716 commit 3bcc2a6

File tree

1 file changed

+52
-7
lines changed

1 file changed

+52
-7
lines changed

MainLoop.cpp

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ using namespace cv;
3131

3232
// opencv
3333
VideoCapture video1;
34+
VideoCapture video2;
3435

3536
// apriltag
3637
apriltag_detector* TagDetector;
@@ -77,9 +78,28 @@ int simu_init(int ScreenWidth, int ScreenHeight)
7778
video1.open(0);
7879
if (video1.isOpened()) printf("camera open successful\n");
7980
else {printf("camera open failed\n"); return -1;}
80-
namedWindow("camera", WINDOW_NORMAL);
81-
moveWindow("camera",ScreenWidth/2,0);
82-
resizeWindow("camera",ScreenWidth/2,ScreenHeight/2);
81+
82+
video1.set(CV_CAP_PROP_FRAME_WIDTH,800);
83+
video1.set(CV_CAP_PROP_FRAME_HEIGHT,600);
84+
//video1.set(CV_CAP_PROP_FRAME_WIDTH,1024);
85+
//video1.set(CV_CAP_PROP_FRAME_HEIGHT,768);
86+
87+
namedWindow("camera1", WINDOW_NORMAL);
88+
moveWindow("camera1",ScreenWidth/2,ScreenHeight/2);
89+
resizeWindow("camera1",ScreenWidth/4,ScreenHeight/2.2);
90+
91+
video2.open(1);
92+
if (video2.isOpened()) printf("camera open successful\n");
93+
else {printf("camera open failed\n"); return -1;}
94+
95+
namedWindow("camera2", WINDOW_NORMAL);
96+
moveWindow("camera2",ScreenWidth/2,0);
97+
resizeWindow("camera2",ScreenWidth/4,ScreenHeight/2.2);
98+
99+
video2.set(CV_CAP_PROP_FRAME_WIDTH,800);
100+
video2.set(CV_CAP_PROP_FRAME_HEIGHT,600);
101+
//video2.set(CV_CAP_PROP_FRAME_WIDTH,1024);
102+
//video2.set(CV_CAP_PROP_FRAME_HEIGHT,768);
83103

84104
// open apriltag
85105
TagDetector = apriltag_detector_create();
@@ -93,10 +113,24 @@ int simu_init(int ScreenWidth, int ScreenHeight)
93113

94114
// apriltag pose estimation
95115
CameraInfo.tagsize = 0.0235;
116+
/*
96117
CameraInfo.fx = 939.001439;
97118
CameraInfo.fy = 939.001439;
98119
CameraInfo.cx = 320 ;
99120
CameraInfo.cy = 240;
121+
*/
122+
123+
CameraInfo.fx = 796.9096;
124+
CameraInfo.fy = 796.9096;
125+
CameraInfo.cx = 400;
126+
CameraInfo.cy = 300;
127+
128+
/*
129+
CameraInfo.fx = 1039.4975;
130+
CameraInfo.fy = 1039.4975;
131+
CameraInfo.cx = 512;
132+
CameraInfo.cy = 384;
133+
*/
100134

101135
return 0;
102136
}
@@ -105,11 +139,20 @@ int simu_step(double time) // time in s
105139
{
106140
printf("--------step----------\n");
107141
// ----------------- opencv capture ------------------------- //
108-
Mat imgRGB, imgGRAY;
142+
Mat imgRGB800, imgRGB, imgGRAY;
109143
// capture image
110-
//video1 >> imgRGB;
111-
imgRGB = imread("../failure.jpg");
144+
video1 >> imgRGB800;
145+
//imgRGB = imread("../failure.jpg");
146+
147+
Rect crop(100, 0, 600, 600);
148+
imgRGB = imgRGB800(crop);
149+
112150
cvtColor(imgRGB, imgGRAY, CV_BGR2GRAY);
151+
152+
Mat imgRGB8002, imgRGB2, imgGRAY2;
153+
video2 >> imgRGB8002;
154+
imgRGB2 = imgRGB8002(crop);
155+
113156
// ----------------- apriltag detect ------------------------- //
114157
image_u8_t* imgU8Y = image_u8_create(imgGRAY.cols, imgGRAY.rows);
115158
for (unsigned int row = 0; row < imgU8Y->height; row++)
@@ -121,6 +164,7 @@ int simu_step(double time) // time in s
121164

122165
// get detections
123166
nTags = zarray_size(psDetections);
167+
printf("detect number: %d\n", nTags);
124168
for (int i = 0; i < nTags; i++)
125169
{
126170
// get detection
@@ -172,7 +216,8 @@ int simu_step(double time) // time in s
172216
}
173217

174218
// ----------------- opencv show ----------------------------- //
175-
imshow("camera", imgRGB);
219+
imshow("camera1", imgRGB);
220+
imshow("camera2", imgRGB2);
176221
waitKey(1);
177222
return 0;
178223
}

0 commit comments

Comments
 (0)