Aruco tutorial code does not compile - opencv

Hello I am getting an error when using aruco. I am just trying to get an example from the tutorial working. I did everything according to the tutorial but I get:
/home/pi/Programs/markerDetection/markerDetection.cpp: In function ‘int main(int, char**)’:
/home/pi/Programs/markerDetection/markerDetection.cpp:26:104: error: invalid initialization of reference of type ‘cv::Ptr<cv::aruco::Dictionary>&’ from expression of type ‘cv::aruco::Dictionary’
aruco::detectMarkers(inputImage, dictionary, markerCorners, markerIds, parameters, rejectedCandidates);
^
In file included from /home/pi/Programs/markerDetection/markerDetection.cpp:6:0:
/home/pi/opencv/include/opencv2/aruco.hpp:176:19: note: in passing argument 2 of ‘void cv::aruco::detectMarkers(cv::InputArray, cv::Ptr<cv::aruco::Dictionary>&, cv::OutputArrayOfArrays, cv::OutputArray, const cv::Ptr<cv::aruco::DetectorParameters>&, cv::OutputArrayOfArrays)’
CV_EXPORTS_W void detectMarkers(InputArray image, Ptr<Dictionary> &dictionary, OutputArrayOfArrays corners,
^
CMakeFiles/marker.dir/build.make:54: recipe for target 'CMakeFiles/marker.dir/markerDetection.cpp.o' failed
make[2]: *** [CMakeFiles/marker.dir/markerDetection.cpp.o] Error 1
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/marker.dir/all' failed
make[1]: *** [CMakeFiles/marker.dir/all] Error 2
Makefile:76: recipe for target 'all' failed
make: *** [all] Error 2
My code is:
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/videoio/videoio.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/aruco.hpp"
#include <vector>
using namespace cv;
using namespace std;
int main (int argc, char** argv)
{
VideoCapture cap;
if(!cap.open(0)){
return 0;
}
for(;;){
Mat inputImage;
cap >> inputImage;
vector< int > markerIds;
vector< vector<Point2f> > markerCorners, rejectedCandidates;
aruco::DetectorParameters parameters;
aruco::Dictionary dictionary = aruco::getPredefinedDictionary(aruco::DICT_6X6_250);
aruco::detectMarkers(inputImage, dictionary, markerCorners, markerIds, parameters, rejectedCandidates);
Mat outputImage;
aruco::drawDetectedMarkers(outputImage, markerCorners, markerIds);
if(inputImage.empty()) break;
imshow("Webcam", outputImage);
if(waitKey(1) >= 0) break;
}
return 0;
}
I know there are too many includes and the code needs some work but I just need it to compile and I have no idea what is happening there. Has the function changed?

The following code works for me:
Dictionary declaration:
cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
As the function getPredefinedDictionary returns a Ptr<Dictionary>
(http://docs.opencv.org/trunk/d9/d6a/group__aruco.html)
To detect markers:
cv::aruco::detectMarkers(gray, dictionary, marker_corners, marker_ids);

I had the same problem as you. Here is what did the trick:
instead of:
aruco::DetectorParameters parameters;
aruco::Dictionary dictionary=aruco::getPredefinedDictionary(aruco::DICT_6X6_250);
use:
cv::Ptr<aruco::DetectorParameters> parameters;
cv::Ptr<aruco::Dictionary> dictionary=aruco::getPredefinedDictionary(aruco::DICT_6X6_250);
I hope it helps you.

I was missing some include files. These are the ones I have now:
#include "opencv2/aruco.hpp"
#include <iostream>
#include <stdio.h>
#include <opencv2/highgui.hpp>
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core.hpp"
#include "opencv2/videoio/videoio.hpp"
#include <vector>
And the libraries are (these are included in Project-> Properties->settings->Linker->Input ):
opencv_core450.lib
opencv_highgui450.lib
opencv_objdetect450.lib
opencv_videoio450.lib
opencv_imgproc450.lib
opencv_imgcodecs450.lib
opencv_aruco450.lib
opencv_core450d.lib
opencv_highgui450d.lib
opencv_objdetect450d.lib
opencv_videoio450d.lib
opencv_imgproc450d.lib
opencv_imgcodecs450d.lib
opencv_aruco450d.lib
The opencv_aruco450.lib was not getting properly saved as far as I know. This was my problem.

Related

How to set LLVM &AnalysisType::ID For Analysis Pass

I'm trying to create an analysis pass. My code is shown below. I'm using Adrian Sampson approach for building the .so file (https://www.cs.cornell.edu/~asampson/blog/llvm.html).
#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "DataDependence.h"
#include "ControlDependence.h"
#include "llvm/IR/Module.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/Analysis/MemoryDependenceAnalysis.h"
#include "llvm/Analysis/LoopInfo.h"
using namespace llvm;
namespace {
struct SkeletonPass : public ModulePass {
static char ID;
SkeletonPass() : ModulePass(ID) {}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<LoopInfoWrapperPass>();
AU.addRequired<DominatorTreeWrapperPass>();
// AU.addPreserved<AliasAnalysis>();
// AU.setPreservesCFG();
// AU.addRequired<PostDominatorTree>();
}
virtual bool runOnModule(Module &M);
};
bool SkeletonPass::runOnModule(Module &M) {
for (auto mi = M.begin(); mi != M.end(); ++mi) {
if (mi->isDeclaration())
continue;
// MemoryDependenceAnalysis &MDA = getAnalysis<MemoryDependenceAnalysis>(*mi);
PostDominatorTree &PDT = getAnalysis<PostDominatorTree>(*mi); //Error is Here
}
errs() << "Test:\n";
}
}
char SkeletonPass::ID = 0;
static RegisterPass<SkeletonPass> X("SkeletonPass", "Hello World Pass",
false /* Only looks at CFG */,
true /* Analysis Pass */);
The error I'm getting is below
In file included from /usr/local/include/llvm/Pass.h:388:0,
from /media/quentinmayo/storage/Research/LLVM Dev/llvm-pass-skeleton/skeleton/Skeleton.cpp:1:
/usr/local/include/llvm/PassAnalysisSupport.h: In instantiation of ‘AnalysisType& llvm::Pass::getAnalysis(llvm::Function&) [with AnalysisType = llvm::PostDominatorTree]’:
/media/quentinmayo/storage/Research/LLVM Dev/llvm-pass-skeleton/skeleton/Skeleton.cpp:34:71: required from here
/usr/local/include/llvm/PassAnalysisSupport.h:253:38: error: ‘ID’ is not a member of ‘llvm::PostDominatorTree’
return getAnalysisID<AnalysisType>(&AnalysisType::ID, F);
^
skeleton/CMakeFiles/SkeletonPass.dir/build.make:62: recipe for target 'skeleton/CMakeFiles/SkeletonPass.dir/Skeleton.cpp.o' failed
make[2]: *** [skeleton/CMakeFiles/SkeletonPass.dir/Skeleton.cpp.o] Error 1
CMakeFiles/Makefile2:85: recipe for target 'skeleton/CMakeFiles/SkeletonPass.dir/all' failed
make[1]: *** [skeleton/CMakeFiles/SkeletonPass.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
The error is saying I'm missing AnalysisType::ID. I would like to pass the AliasAnalysis pointer to another class for analysis. I'm confused what this AnalysisType::ID would be? Additionally, can someone explain the relationship between getAnalysisUsage and getAnalysis when creating pass for analysis? Understanding compiler theory doesn't really help me with working with LLVM.
http://llvm.org/docs/doxygen/html/classllvm_1_1Pass.html#ab78af013d3a11515403da8517f8f3d4a
I needed to call the class member getDomTree .
DominatorTree &DI = getAnalysis(*mi).getDomTree();
Advice for others: get friendly with the doxygen pages and reading header files. And if it comes to it, look into the source of your current LLVM build.
Also,AliasAnalysis is now AAResultsWrapperPass.

matlab stops working when getting printf order from a mex file

i am new to C++ and coding
how ever i attemped to make a mex file to use in matlab
the mex file has a problem for printing a parameter
i have sent the error picture
the code also is as below
`#include <windows.h>
#include <mex.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdint.h>
#include "./mavlink/v1.0/common/mavlink.h" //MAV_CMD_COMPONENT_ARM_DISARM is just defined
#include "C:\Users\SONY\Documents\Visual Studio 2010\Projects\code_test_2/inttypes.h"
#define STRICTfstat
#define WIN32_LEAN_AND_MEAN
#define CALL_TYPE_INIT 0
#define CALL_TYPE_CODE 1
#define CALL_TYPE_DECODE 2
#define CALL_TYPE_ARM 3
#define CALL_TYPE_DISARM 4
#ifndef MAV_CMD_COMPONENT_ARM_DISARM
#define MAV_CMD_COMPONENT_ARM_DISARM 400
#endif
unsigned char buf[4096]; // we put send and recive data in it enshaallah
int receive_chan = 0;
int system_id = 0;
int component_id = 0;
int APM_Sys_ID=0; // we use it instead of target sys ID
int APM_Comp_ID=0; // we use it instead of target component ID
mavlink_status_t status_copy;
mavlink_heartbeat_t system_heart_beat;
mavlink_message_t msg;
mavlink_attitude_t attitude; // it specifies the type of attitude. it says attitude is a data of type mavlink_attitude (hosein)
mavlink_rc_channels_raw_t rc_channels_raw;
void mexFunction(
int nlhs,
mxArray *plhs[],
int nrhs,
mxArray *prhs[]
)
{
double *CALL_TYPE = mxGetPr(prhs[0]);
if (*CALL_TYPE == CALL_TYPE_CODE){
uint16_t chan1_raw,chan2_raw,chan3_raw,chan4_raw,chan5_raw,chan6_raw,chan7_raw,chan8_raw;
printf("salam\n");
double *Actuators = mxGetPr(plhs[1]); // here we get the Actuators value which is prepared in matlab (it is sent from matlab to visula studio)
chan1_raw=1000*Actuators[0+8*0]+1000;
//chan2_raw=1000*Actuators[1+8*0]+1000;
//chan3_raw=1000*Actuators[2+8*0]+1000;
//chan4_raw=1000*Actuators[3+8*0]+1000;
//chan5_raw=1000*Actuators[4+8*0]+1000;
//chan6_raw=1000*Actuators[5+8*0]+1000;
//chan7_raw=1000*Actuators[6+8*0]+1000;
//chan8_raw=1000*Actuators[7+8*0]+1000;
/*mavlink_msg_rc_channels_override_pack(
system_id,
component_id,
&msg,//msg is out put and it is the way mavlink has determined and ali has no role on it
APM_Sys_ID,//we replaced target_system with APM_Sys_ID (this is the change we made in original code)
APM_Comp_ID,
chan1_raw,
chan2_raw,
chan3_raw,
chan4_raw,
chan5_raw,
chan6_raw,
chan7_raw,
chan8_raw);
*/
printf("% PRIu16\n",chan1_raw);
//printf("%i",chan2_raw);
//printf("%i",chan3_raw);
//printf("%i",chan4_raw);
//printf("%i",chan5_raw);
//printf("%i",chan6_raw);
}
}`
so please give me help for solving this problem if it is possible

What is wrong with this OpenCv code?

I am trying frame difference in this opencv code (C API).
It gives me an error:
Assertion failed (src1.size() == dst.size() && src1.type() == dst. type()) in unknown function, file ........\ocv\opencv\src\cxcore\cxarithm.cpp , line 1563.
The code is as follow. (When I try to run a video file, this program seems to run without any error, but when I am trying to capture from laptop camera, it gives this error. How do I fix this?
#include "stdafx.h"
#include <cv.h>
#include <highgui.h>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
int key=0;
//CvCapture *capture=cvCreateCameraCapture(0);
CvCapture *capture=cvCaptureFromAVI("cmake.avi");
IplImage *frame=cvQueryFrame(capture);
IplImage *currframe=cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U,3);
IplImage *dstframe=cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U,3);
int fps = ( int )cvGetCaptureProperty( capture, CV_CAP_PROP_FPS );
cvNamedWindow("output",CV_WINDOW_NORMAL);
while(key!='x'){
currframe=cvCloneImage(frame);
frame=cvQueryFrame(capture);
//cvCopy(frame,currframe,0);
frame=cvQueryFrame(capture);
cvSub(frame,currframe,dstframe);
if(key==27) break;
cvShowImage("output",dstframe);
key = cvWaitKey( 1000 / fps );
}
cvReleaseCapture(&capture);
cvDestroyWindow("output");
return 0;
}
The error is saying that you are trying to do an operation that needs images of the same size and type. If you run your code in a debugger you can see which line this occurs on.
It is probably one of the destination images you are creating. A t least in the C++ api it is best not to create destination images but just declare them and let the function allocate what it needs

Assertion error with imshow

OK, i know this question may not be new and I've already gone through a few posts covering the same issue but it hasn't really helped. I am new to opencv and I am trying to load an image (in a folder that's different from the one where the executable file's stored) using imread and display it using imshow. Its the part of a much bigger code but I've shown the part that covers the issue as a separate code here:
#include <stdio.h>
#include "cv.h"
#include "cvaux.h"
#include "highgui.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include <iostream>
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/highgui/highgui_c.h"
#include "opencv/highgui.h"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/legacy/legacy.hpp"
#include <fstream>
#include <sstream>
#include <cctype>
#include <iterator>
#include <cstring>
#include <highgui.h>
#include <string.h>
int disp(char * filename);
using namespace std;
using namespace cv;
int main()
{
disp("file.txt");
}
int disp(char * filename)
{
FILE * fp;
char shr[50];
char ch;
if( !(fp = fopen(filename, "rt")) )
{
fprintf(stderr, "Can\'t open file %s\n", filename);
return 0;
}
for(i=0;ch != '\n';i++)
{
ch = fgetc(imgListFile);
shr[i] = ch;
}
string str(shr);
Mat image=imread(str.c_str(),1);
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
imshow( "Display Image",image);
cvWaitKey(0);
}
The "file.txt" is a text file containing the full path of the image i want to load and display. I am reading it into a character array, converting it to a string and passing it to the imshow/imread functions. I am not getting any errors while compiling, however, i am getting an error while i run the code:
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/ubuntu/Desktop/OpenCV/opencv-2.4.6.1/modules/highgui/src/window.cpp, line 261
terminate called after throwing an instance of 'cv::Exception'
what(): /home/ubuntu/Desktop/OpenCV/opencv-2.4.6.1/modules/highgui/src/window.cpp:261: error: (-215) size.width>0 && size.height>0 in function imshow
Aborted (core dumped)
I tried debugging the code, even re-compiled opencv; but i am getting the same issue again & again. I need help !!!
Hope i've explained my issue properly. Thanks in advance !!!
P.S: The text file actually contains a number before every image path; and i need to remove the number before i can feed the path to the imshow/imread functions; that's the reason i am trying to read the text file and store in a character array (so that i can get rid of the first 2 characters first).
The error message tells you that the image a 0 rows and/or 0 columns. This is usually caused by an incorrect path to image, or by an an image type that is not handled by your installation of OpenCV.
To debug it, you need to print out the argument of imread() and compare it with the catual location of the file on your system.
your for loop here is broken:
for(i=0;ch != '\n';i++)
{
ch = fgetc(imgListFile);
// you have to check the value of ch *after* reading
if ( ch == '\n' )
break; // else, you still append the '\n' to your filename
shr[i] = ch;
}
// z terminate
shr[i] = 0;
so, - you get empty images because of broken path.
There are some typos in your code. Also, it appears as if you haven't completely grasped the concepts of file handling and string allocations using c++; I would advise you to read up on those.. I have re-written your code as follows,
int main()
{
disp("file.txt");
return EXIT_SUCCESS;
}
void disp(char* filename)
{
ifstream myReadFile;
char shr[500];
myReadFile.open(filename);
if(myReadFile.is_open())
while(!myReadFile.eof())
myReadFile >> shr;
string str(shr);
Mat image=imread(str.c_str(),1);
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
imshow( "Display Image",image);
cvWaitKey(0);
}
Hope this helps.

glib compilation with ios

I am trying to compile glib in ios, i have got an error in gio/tests/appinfo-test.h
#include <stdlib.h>
#include <gio/gio.h>
int
main (int argc, char *argv[])
{
const gchar *envvar;
gint pid_from_env;
envvar = g_getenv ("GIO_LAUNCHED_DESKTOP_FILE_PID");
g_assert (envvar != NULL);
pid_from_env = atoi (envvar);
g_assert_cmpint (pid_from_env, ==, getpid ());
envvar = g_getenv ("GIO_LAUNCHED_DESKTOP_FILE");
g_assert_cmpstr (envvar, ==, SRCDIR "/appinfo-test.desktop"); //got the error here that "Use of undefined identifier 'SRCDIR' "
return 0;
}
please help me out...Thank you
I can not figure out with given information how you tried to compile the sample code in your ios, but you can add
#define SRCDIR
before main().
The sample code seems to be glib/gio/tests/appinfo-test.c in the source repository. SRCDIR is defined as -DSRCDIR=\""$(srcdir)"\" in the Makefile.am.

Resources