Some error about calling a .mexw64 file in Matlab code - c++

Recently,I used Mex to compile some .cpp file into .mexw64.
The following is the specific process:
1)I put mexResize.cpp MxArray.cpp and MxArray.h into a folder;
2)Then I run a make.m and get a mexResize.mexw64 in the folder above:
Command window of matlab
3)Finally I use mexResize.mexw64 in my matlab code:
img1 = mexResize(img,[100,100]);
However,I met the error like the following:
Error information
There are some Chinese sentences above,I try to translate them as following:
"MEX The file appears unexpected standard exceptions"
"Error test (line 3)"
Apologize for my limited English.

Related

mex file compiled successfuly. DependencyWalker cannot find many of the dlls

I have compiled a mex file using MATLAB. I am having trouble since every time I try to run the code, MATLAB crushes.
I have tried using feval() function with a mexhost in order to separate the processes and debug, following this guide. When I am executing using feval(mh,'functionName',input), all I am getting is:
Invalid C++ MEX-file 'test_c'
However, when I am executing using feval(mh,functionName,input) I am getting an nrhs of size 0.
I have followed throw with this guide and used the DependancyWalker utility to get the following result:
A lot of the DLLs are missing. Even the basic LIBMEX.DLL can't be found. Am I doing something wrong here? How do I debug?
Probably some of MATLAB's folders aren't in your system path variable (%PATH% on Windows).

Opencv Create Samples .vec file was not created

I'm trying to make a .vec file for using to create my cascade training XML file. While trying to run the code, I see an error and I couldn't find any answer about this.
May you help me, please?
The error is like that:
Unable to open image: pozitif1.jpg OpenCV Error: Unknown error code -9
() in cvSetImageROI, file
C:\build\master_winpack-build-win64-vc14\opencv\modules\core\src\array.cpp,
line 3021

rmarkdown error: "myfile.tex"' had status 1

I am trying to compile an RMarkdown document from an R script. This is the code I am running:
setwd("C:/Users/me/me_VN02_5676/myfolder")
rmarkdown::render("myrmd.Rmd",
output_file = "mypdf.pdf")
This results in the error:
Error: Failed to compile mypdf.tex.
In addition: Warning message:
running command '"pdflatex" -halt-on-error -interaction=batchmode "mypdf.tex"' had status 1
Does anyone know what is happening?
Additional Notes
The PDF file is created when I use the Knit button in RStudio
This code does produce the .Tex file and when I run that it produces the pdf but render() does not produce the pdf
When I run the .R file via the command line it works! The PDF is created but why doesn't it work in R studio?
It would help to provide a Minimal Working Example so that we can attempt to replicate the problem. However, there may be two potential causes:
File Paths Look Incorrect
In R, they should be specified with a single forward slash: https://stat.ethz.ch/R-manual/R-devel/library/base/html/file.path.html
setwd("C:/Users/me/me_VN02_5676/myfolder")
rmarkdown::render("myrmd.Rmd",
output_file = paste0("mypdf.pdf")
)
PDF Output File May be Open
Another potential cause of this is that the PDF file is open, and therefore pandoc cannot save the output PDF. Try closing the PDF and render the document again.
Link to previous issue in Knitr which relates to this: https://github.com/yihui/knitr/issues/1209

Can't run an executable file in matlab with system(), but it works in command line

I need to run a C++ executable file which uses the OPencv library using the system command in Matlab. I already compile all the code with make and it was successful. When I run the program in command line it works as shown below.
lib/sift/bin/siftfeat -x -o tampered1.txt tampered1.jpg
Finding SIFT features...
Found 2596 features.
The problem is when I run it with matlab. The following error happens:
>>system('lib/sift/bin/siftfeat -x -o tampered1.txt tampered1.jpg')
Finding SIFT features...
Error: unable to load image from tampered1.jpg
lib/sift/bin/siftfeat -x -o tampered1.txt tampered1.jpg: Aborted
The error happens in lib/sift/src/siftfeat.c in the following piece of code:
fprintf( stderr, "Finding SIFT features...\n" );
img = cvLoadImage( img_file_name, 1 );
if( ! img )
fatal_error( "unable to load image from %s", img_file_name );
Why does this happen? I mean, if the code runs in command line, why it doesn't run with system Matlab command? doesn't matlab recognize the cvLoadImage function? I am using Matlab R2014a and OPencv-2.4.9. This code was copied from another PC and I just recompiled it. In the original PC in which the code was copied the system command works.
You are running the system()-cmd in the wrong folder.
While you call your binary with an absolute path, the path to your images are relative.
Therefore, the images need to be in the folder, where matlab executes your system()-cmd.
You can simply check this by executing:
>> system('pwd')
"Folder/where/matlab/exec/your/cmd"
If the output corresponds to your image location, everything should be fine, otherwise you have to give your program the absolute path like this:
>> system('lib/sift/bin/siftfeat -x -o Folder/to/your/txt/tampered1.txt Folder/to/your/image/tampered1.jpg')
I tried it, and found that using sudo will work.

vlfeat matlab error Attempt to execute SCRIPT vl_imsmooth as a function:

I am trying to use the VLFEAT function vl_imsmooth but matlab gives me an error:
'Attempt to execute SCRIPT vl_imsmooth as a function:'
Why this happens?
Might it be because of some mex files?
Should I recompile the c++ code for vl_feat?
The problem shuold be fixed by copying correct mexw32 or mexw64 file folder from ..\vlfeat\toolbox\mex to ..\vlfeat. In my case my operating system is 64 bit My folder looks like ..\vlfeat\mexw64
You are getting this error because your path ".../vlfeat-0.9.16/toolbox/imop/vl_imsmooth.m"
has a higher precedence than " ...../vlfeat-0.9.16/toolbox/mex/mexa64/vl_imsmooth.mexa64"
so you can simply run
pathtool
and then navigate the mexa64 path above the imop and you are done !!