Comments (5)
Very interesting. I'll add special treating for creating mxLOGICAL_CLASS array.
from mexopencv.
The last commit added thresholding to saturate all nonzero values to 1 in the conversion. Hope it fixes the issue.
from mexopencv.
while your commit solves the above case, cv::threshold
has a couple of issues:
- it only works with
CV_8U
,CV_16S
,CV_32F
types. Anything else throws an exception. - when converting from signed types, negative values get saturated at zero (false). Note that in MATLAB,
logical(-1) == logical(1) == true
, and onlylogical(0) == false
As far as I can tell, a better solution would be:
cv::compare(input, 0, input, cv::CMP_NE); // input = uint8( 255 * (input~=0) )
cv::min(input, 1, input); // input = min(input,1)
by comparing the matrix against scalar zero (result is of type CV_8UC1
set to 255 where nonzero), then using cv::min
to cap at 1.
Here is a test to confirm (should return: [true,false,true]
ie logical([1,0,1])
):
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double x[] = {-5.0, 0.0, 5.0};
cv::Mat m(1, 3, CV_64FC1, (void*)x);
plhs[0] = MxArray(m, mxLOGICAL_CLASS);
}
from mexopencv.
That makes sense. I have included the fix in the last commit, with a slight modification of the use of cv::setTo rather than cv::min.
Perhaps it's a TODO to prepare a unit test for MxArray.
from mexopencv.
thanks, that should do it. Unit-testing the MxArray layer sounds like a good idea..
from mexopencv.
Related Issues (20)
- Mexopencv using MatLab Runtime
- Using homebrew to install OpenCV==3.4.1
- windows opencv3.4.1 cmake
- Setting up mexopencv for matlab 2018b HOT 2
- No output from cv.getBuildInformation() in Octave 5.1.0
- maybe bug about the queryIdx and trainIdx
- ld: symbol(s) not found for architecture x86_64
- Invalid MEX-file : Missing dependent shared libraries
- [error 3] gcc >= 4.4 g++ >= 4.4 is installed
- v3.2.0 and xfeatures2d HOT 1
- mexopencv not compiling HOT 2
- error in setup opencv and mexopencv
- how Mac to mexopencv HOT 1
- [lib/mexopencv_features2d.o] Error 255 HOT 1
- MxArray::toMoments out of order arguments to cv::Moments
- Consider leveraging MATLAB in your CI
- MATLAB Error: Unrecognized function or variable 'FeaturesFinder_'.
- why can't I use the 'cv.detectMarkers' function???
- Hi all, I have a big problem when I am using matlab R2021a to builed mexopencv. HOT 1
- mexopencv building error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mexopencv.