7 #import "VispDetector.h" 8 #import "ImageConversion.h" 9 #import "ImageDisplay+withContext.h" 15 - (UIImage *)detectAprilTag:(UIImage *)image px:(
float)px py:(
float)py {
24 if(px == 0.0 && py == 0.0){
30 float quadDecimate = 3.0;
32 double tagSize = 0.043;
39 std::vector<vpHomogeneousMatrix> cMo_vec;
40 detector.
detect(I, tagSize, cam, cMo_vec);
43 UIGraphicsBeginImageContext(image.size);
44 CGContextRef context = UIGraphicsGetCurrentContext();
47 [image drawAtPoint:CGPointMake(0,0)];
51 for(
int i=0; i < tagNums; i++){
54 std::vector<vpImagePoint> polygon = detector.
getPolygon(i);
57 UIColor *mainColor = [UIColor blueColor];
58 int tagLineWidth = 10;
61 NSString * message = [NSString stringWithCString:detector.getMessage(i).c_str() encoding:[NSString defaultCStringEncoding]];
62 NSArray *phases = [message componentsSeparatedByString:@" "];
63 int detectedTagId = [phases[2] intValue];
66 NSString *tagIdStr = [NSString stringWithFormat:@"%d", detectedTagId];
67 [ImageDisplay displayText:tagIdStr :polygon[0].get_u() :polygon[0].get_v() - 50 :600 :100 :mainColor :[UIColor clearColor]];
70 [ImageDisplay displayLineWithContext:context :polygon :mainColor :tagLineWidth];
73 [ImageDisplay displayFrameWithContext:context :cMo_vec[i] :cam :tagSize :6];
76 NSString *meter = [NSString stringWithFormat:@"(%.2f,%.2f,%.2f)",trans[0],trans[1],trans[2]];
77 [ImageDisplay displayText:meter :cog.get_u() :cog.get_v() +50 :600 :100 :[UIColor whiteColor] :[UIColor blueColor]];
80 image = UIGraphicsGetImageFromCurrentImageContext();
81 UIGraphicsEndImageContext();
AprilTag 36h11 pattern (recommended)
size_t getNbObjects() const
void setAprilTagQuadDecimate(float quadDecimate)
Generic class defining intrinsic camera parameters.
void setAprilTagNbThreads(int nThreads)
vpImagePoint getCog(size_t i) const
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
unsigned int getHeight() const
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
unsigned int getWidth() const
Class that consider the case of a translation vector.
std::vector< std::vector< vpImagePoint > > & getPolygon()
bool detect(const vpImage< unsigned char > &I)