Why is my app crashing when I try to invert a UIImage in openCV?
up vote
0
down vote
favorite
I have been playing around with this now for a long time and I can't get the following code going for some reason.
+(UIImage *)processInvertedImage:(UIImage *)image
cv::Mat mat;
UIImageToMat(image, mat); ///this is CV_8U from iPhone camera
cv::Mat output;
mat.convertTo(output, CV_32F); ///cv::invert() requires CV_32F!! (apparently)
cv::Mat invert;
cv::invert(output, invert); /// app crashes here, error message below
cv::Mat gray;
cv::cvtColor(invert, gray, CV_RGB2GRAY);
UIImage *binImg = MatToUIImage(gray);
return binImg;
I am getting the following error code:
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.2) /Volumes/build-storage/build/3_4_iOS-mac/opencv/modules/core/src/lapack.cpp:839: error: (-215:Assertion failed) type == 5 || type == 6 in function 'invert'
what does this type == 5 || type == 6 mean?
opencv image-processing
add a comment |
up vote
0
down vote
favorite
I have been playing around with this now for a long time and I can't get the following code going for some reason.
+(UIImage *)processInvertedImage:(UIImage *)image
cv::Mat mat;
UIImageToMat(image, mat); ///this is CV_8U from iPhone camera
cv::Mat output;
mat.convertTo(output, CV_32F); ///cv::invert() requires CV_32F!! (apparently)
cv::Mat invert;
cv::invert(output, invert); /// app crashes here, error message below
cv::Mat gray;
cv::cvtColor(invert, gray, CV_RGB2GRAY);
UIImage *binImg = MatToUIImage(gray);
return binImg;
I am getting the following error code:
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.2) /Volumes/build-storage/build/3_4_iOS-mac/opencv/modules/core/src/lapack.cpp:839: error: (-215:Assertion failed) type == 5 || type == 6 in function 'invert'
what does this type == 5 || type == 6 mean?
opencv image-processing
Not a duplicate, but very similar question here. You have exactly his problem. See my answer and comment for details.
– Quang Hoang
Nov 9 at 1:36
Hi Quang, yes, that was my question yesterday. Just needed to ask it again since after I introduced your suggestions it actually still does not work.
– kangarooChris
Nov 9 at 2:00
you suggested the conversion to CV_32F, but still crashing with exactly the same error message, so there must be something else going on here.
– kangarooChris
Nov 9 at 2:02
wouldn't it be better to convert to gray scale and then do the invert function?? with invert requiring CV_23F is that then possible at all?
– kangarooChris
Nov 9 at 2:04
I didn't notice the same poster. I am adding an answer here.
– Quang Hoang
Nov 9 at 2:05
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have been playing around with this now for a long time and I can't get the following code going for some reason.
+(UIImage *)processInvertedImage:(UIImage *)image
cv::Mat mat;
UIImageToMat(image, mat); ///this is CV_8U from iPhone camera
cv::Mat output;
mat.convertTo(output, CV_32F); ///cv::invert() requires CV_32F!! (apparently)
cv::Mat invert;
cv::invert(output, invert); /// app crashes here, error message below
cv::Mat gray;
cv::cvtColor(invert, gray, CV_RGB2GRAY);
UIImage *binImg = MatToUIImage(gray);
return binImg;
I am getting the following error code:
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.2) /Volumes/build-storage/build/3_4_iOS-mac/opencv/modules/core/src/lapack.cpp:839: error: (-215:Assertion failed) type == 5 || type == 6 in function 'invert'
what does this type == 5 || type == 6 mean?
opencv image-processing
I have been playing around with this now for a long time and I can't get the following code going for some reason.
+(UIImage *)processInvertedImage:(UIImage *)image
cv::Mat mat;
UIImageToMat(image, mat); ///this is CV_8U from iPhone camera
cv::Mat output;
mat.convertTo(output, CV_32F); ///cv::invert() requires CV_32F!! (apparently)
cv::Mat invert;
cv::invert(output, invert); /// app crashes here, error message below
cv::Mat gray;
cv::cvtColor(invert, gray, CV_RGB2GRAY);
UIImage *binImg = MatToUIImage(gray);
return binImg;
I am getting the following error code:
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.2) /Volumes/build-storage/build/3_4_iOS-mac/opencv/modules/core/src/lapack.cpp:839: error: (-215:Assertion failed) type == 5 || type == 6 in function 'invert'
what does this type == 5 || type == 6 mean?
opencv image-processing
opencv image-processing
asked Nov 9 at 1:07
kangarooChris
198214
198214
Not a duplicate, but very similar question here. You have exactly his problem. See my answer and comment for details.
– Quang Hoang
Nov 9 at 1:36
Hi Quang, yes, that was my question yesterday. Just needed to ask it again since after I introduced your suggestions it actually still does not work.
– kangarooChris
Nov 9 at 2:00
you suggested the conversion to CV_32F, but still crashing with exactly the same error message, so there must be something else going on here.
– kangarooChris
Nov 9 at 2:02
wouldn't it be better to convert to gray scale and then do the invert function?? with invert requiring CV_23F is that then possible at all?
– kangarooChris
Nov 9 at 2:04
I didn't notice the same poster. I am adding an answer here.
– Quang Hoang
Nov 9 at 2:05
add a comment |
Not a duplicate, but very similar question here. You have exactly his problem. See my answer and comment for details.
– Quang Hoang
Nov 9 at 1:36
Hi Quang, yes, that was my question yesterday. Just needed to ask it again since after I introduced your suggestions it actually still does not work.
– kangarooChris
Nov 9 at 2:00
you suggested the conversion to CV_32F, but still crashing with exactly the same error message, so there must be something else going on here.
– kangarooChris
Nov 9 at 2:02
wouldn't it be better to convert to gray scale and then do the invert function?? with invert requiring CV_23F is that then possible at all?
– kangarooChris
Nov 9 at 2:04
I didn't notice the same poster. I am adding an answer here.
– Quang Hoang
Nov 9 at 2:05
Not a duplicate, but very similar question here. You have exactly his problem. See my answer and comment for details.
– Quang Hoang
Nov 9 at 1:36
Not a duplicate, but very similar question here. You have exactly his problem. See my answer and comment for details.
– Quang Hoang
Nov 9 at 1:36
Hi Quang, yes, that was my question yesterday. Just needed to ask it again since after I introduced your suggestions it actually still does not work.
– kangarooChris
Nov 9 at 2:00
Hi Quang, yes, that was my question yesterday. Just needed to ask it again since after I introduced your suggestions it actually still does not work.
– kangarooChris
Nov 9 at 2:00
you suggested the conversion to CV_32F, but still crashing with exactly the same error message, so there must be something else going on here.
– kangarooChris
Nov 9 at 2:02
you suggested the conversion to CV_32F, but still crashing with exactly the same error message, so there must be something else going on here.
– kangarooChris
Nov 9 at 2:02
wouldn't it be better to convert to gray scale and then do the invert function?? with invert requiring CV_23F is that then possible at all?
– kangarooChris
Nov 9 at 2:04
wouldn't it be better to convert to gray scale and then do the invert function?? with invert requiring CV_23F is that then possible at all?
– kangarooChris
Nov 9 at 2:04
I didn't notice the same poster. I am adding an answer here.
– Quang Hoang
Nov 9 at 2:05
I didn't notice the same poster. I am adding an answer here.
– Quang Hoang
Nov 9 at 2:05
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Let me try to answer this one for good. type == 5 || type == 6
means you need to work with CV_32F
or CV_64F
. However, UIImage
usually has 4 channels. I bet your UIImageToMat
yields a mat of type CV_8UC3
. So mat
has type CV_8UC3
, and output
will most likely has type CV_32FC3
, not just CV_32F
. And again, when you use cv::invert()
, you are looking at mathematical inverse, that is output * mat = identity_matrix
.
+(UIImage *)processInvertedImage:(UIImage *)image
cv::Mat mat;
UIImageToMat(image, mat); ///this is CV_8U from iPhone camera
if (mat.type() == CV_8UC3)
NSLog(@"mat type is CV_8UC3"); // mostlikely this
else if (mat.type() == CV_8UC4)
NSLog(@"mat type is CV_8UC4");
cv::Mat output;
mat.convertTo(output, CV_32F); ///cv::invert() requires CV_32F!! (apparently)
if (output.type() == CV_32FC3)
NSLog(@"output type is CV_32FC3"); // most likely this
// this is really bad naming, since you seem to use namespace cv somewhere,
// as CV_32F doesn't have cv:: prefix
cv::Mat invert;
cv::invert(output, invert); /// app crashes here, error message below
cv::Mat gray;
cv::cvtColor(invert, gray, CV_RGB2GRAY);
UIImage *binImg = MatToUIImage(gray);
return binImg;
Edit: If you need image processing inverse, then you can do something similar to what you had in last question:
+(UIImage *)processInvertedImage:(UIImage *)image
cv::Mat mat;
UIImageToMat(image, mat);
// convert to RGB
cv::Mat rgb
cv::cvtColor(mat, rgb, COLOR_RGBA2RGB);
// create mat of same size and type with values 255
cv::Mat dummy(rgb.size(), rgb.type(), cv::Scalar(255,255,255));
// three channels
cv::Mat rgb_invert = dummy ^ rgb;
cv::Mat gray;
cv::cvtColor(rgb, gray, COLOR_RGB2GRAY);
cv::Mat gray_invert = 255 ^ gray;
// depending what invert you would like
UIImage* binImg = MatToUIImage(rgb_invert);
return binImg;
ok, ran it. is is is CV_8UC4. crashed before it came to the CV_32F question
– kangarooChris
Nov 9 at 2:25
1
I believed you when you said it crashed at theinvert
function :D. You can go around bycv::cvtColor(mat, gray, COLOR_RGBA2GRAY)
andgray.convertTo(output, CV_32F)
. But then,invert
will beCV_32F
, notRGB
, i.e.CV_8UC3
. Anyway, I am still not sure why you need mathematical inverse of an image.
– Quang Hoang
Nov 9 at 2:28
I actually don't need mathematical inverse . I misunderstood this. all I want is to change the dark background to light background, which I need for shape recognition. which function do you suggest
– kangarooChris
Nov 9 at 2:31
ran it as per above suggestion and error message has changed now to : libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.2) /Volumes/build-storage/build/3_4_iOS-mac/opencv/modules/core/src/lapack.cpp:863: error: (-215:Assertion failed) m == n in function 'invert'
– kangarooChris
Nov 9 at 2:39
1
That's because only square matrices have mathematical inverses. See edit for image processing inverse.
– Quang Hoang
Nov 9 at 2:47
|
show 1 more comment
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Let me try to answer this one for good. type == 5 || type == 6
means you need to work with CV_32F
or CV_64F
. However, UIImage
usually has 4 channels. I bet your UIImageToMat
yields a mat of type CV_8UC3
. So mat
has type CV_8UC3
, and output
will most likely has type CV_32FC3
, not just CV_32F
. And again, when you use cv::invert()
, you are looking at mathematical inverse, that is output * mat = identity_matrix
.
+(UIImage *)processInvertedImage:(UIImage *)image
cv::Mat mat;
UIImageToMat(image, mat); ///this is CV_8U from iPhone camera
if (mat.type() == CV_8UC3)
NSLog(@"mat type is CV_8UC3"); // mostlikely this
else if (mat.type() == CV_8UC4)
NSLog(@"mat type is CV_8UC4");
cv::Mat output;
mat.convertTo(output, CV_32F); ///cv::invert() requires CV_32F!! (apparently)
if (output.type() == CV_32FC3)
NSLog(@"output type is CV_32FC3"); // most likely this
// this is really bad naming, since you seem to use namespace cv somewhere,
// as CV_32F doesn't have cv:: prefix
cv::Mat invert;
cv::invert(output, invert); /// app crashes here, error message below
cv::Mat gray;
cv::cvtColor(invert, gray, CV_RGB2GRAY);
UIImage *binImg = MatToUIImage(gray);
return binImg;
Edit: If you need image processing inverse, then you can do something similar to what you had in last question:
+(UIImage *)processInvertedImage:(UIImage *)image
cv::Mat mat;
UIImageToMat(image, mat);
// convert to RGB
cv::Mat rgb
cv::cvtColor(mat, rgb, COLOR_RGBA2RGB);
// create mat of same size and type with values 255
cv::Mat dummy(rgb.size(), rgb.type(), cv::Scalar(255,255,255));
// three channels
cv::Mat rgb_invert = dummy ^ rgb;
cv::Mat gray;
cv::cvtColor(rgb, gray, COLOR_RGB2GRAY);
cv::Mat gray_invert = 255 ^ gray;
// depending what invert you would like
UIImage* binImg = MatToUIImage(rgb_invert);
return binImg;
ok, ran it. is is is CV_8UC4. crashed before it came to the CV_32F question
– kangarooChris
Nov 9 at 2:25
1
I believed you when you said it crashed at theinvert
function :D. You can go around bycv::cvtColor(mat, gray, COLOR_RGBA2GRAY)
andgray.convertTo(output, CV_32F)
. But then,invert
will beCV_32F
, notRGB
, i.e.CV_8UC3
. Anyway, I am still not sure why you need mathematical inverse of an image.
– Quang Hoang
Nov 9 at 2:28
I actually don't need mathematical inverse . I misunderstood this. all I want is to change the dark background to light background, which I need for shape recognition. which function do you suggest
– kangarooChris
Nov 9 at 2:31
ran it as per above suggestion and error message has changed now to : libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.2) /Volumes/build-storage/build/3_4_iOS-mac/opencv/modules/core/src/lapack.cpp:863: error: (-215:Assertion failed) m == n in function 'invert'
– kangarooChris
Nov 9 at 2:39
1
That's because only square matrices have mathematical inverses. See edit for image processing inverse.
– Quang Hoang
Nov 9 at 2:47
|
show 1 more comment
up vote
0
down vote
accepted
Let me try to answer this one for good. type == 5 || type == 6
means you need to work with CV_32F
or CV_64F
. However, UIImage
usually has 4 channels. I bet your UIImageToMat
yields a mat of type CV_8UC3
. So mat
has type CV_8UC3
, and output
will most likely has type CV_32FC3
, not just CV_32F
. And again, when you use cv::invert()
, you are looking at mathematical inverse, that is output * mat = identity_matrix
.
+(UIImage *)processInvertedImage:(UIImage *)image
cv::Mat mat;
UIImageToMat(image, mat); ///this is CV_8U from iPhone camera
if (mat.type() == CV_8UC3)
NSLog(@"mat type is CV_8UC3"); // mostlikely this
else if (mat.type() == CV_8UC4)
NSLog(@"mat type is CV_8UC4");
cv::Mat output;
mat.convertTo(output, CV_32F); ///cv::invert() requires CV_32F!! (apparently)
if (output.type() == CV_32FC3)
NSLog(@"output type is CV_32FC3"); // most likely this
// this is really bad naming, since you seem to use namespace cv somewhere,
// as CV_32F doesn't have cv:: prefix
cv::Mat invert;
cv::invert(output, invert); /// app crashes here, error message below
cv::Mat gray;
cv::cvtColor(invert, gray, CV_RGB2GRAY);
UIImage *binImg = MatToUIImage(gray);
return binImg;
Edit: If you need image processing inverse, then you can do something similar to what you had in last question:
+(UIImage *)processInvertedImage:(UIImage *)image
cv::Mat mat;
UIImageToMat(image, mat);
// convert to RGB
cv::Mat rgb
cv::cvtColor(mat, rgb, COLOR_RGBA2RGB);
// create mat of same size and type with values 255
cv::Mat dummy(rgb.size(), rgb.type(), cv::Scalar(255,255,255));
// three channels
cv::Mat rgb_invert = dummy ^ rgb;
cv::Mat gray;
cv::cvtColor(rgb, gray, COLOR_RGB2GRAY);
cv::Mat gray_invert = 255 ^ gray;
// depending what invert you would like
UIImage* binImg = MatToUIImage(rgb_invert);
return binImg;
ok, ran it. is is is CV_8UC4. crashed before it came to the CV_32F question
– kangarooChris
Nov 9 at 2:25
1
I believed you when you said it crashed at theinvert
function :D. You can go around bycv::cvtColor(mat, gray, COLOR_RGBA2GRAY)
andgray.convertTo(output, CV_32F)
. But then,invert
will beCV_32F
, notRGB
, i.e.CV_8UC3
. Anyway, I am still not sure why you need mathematical inverse of an image.
– Quang Hoang
Nov 9 at 2:28
I actually don't need mathematical inverse . I misunderstood this. all I want is to change the dark background to light background, which I need for shape recognition. which function do you suggest
– kangarooChris
Nov 9 at 2:31
ran it as per above suggestion and error message has changed now to : libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.2) /Volumes/build-storage/build/3_4_iOS-mac/opencv/modules/core/src/lapack.cpp:863: error: (-215:Assertion failed) m == n in function 'invert'
– kangarooChris
Nov 9 at 2:39
1
That's because only square matrices have mathematical inverses. See edit for image processing inverse.
– Quang Hoang
Nov 9 at 2:47
|
show 1 more comment
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Let me try to answer this one for good. type == 5 || type == 6
means you need to work with CV_32F
or CV_64F
. However, UIImage
usually has 4 channels. I bet your UIImageToMat
yields a mat of type CV_8UC3
. So mat
has type CV_8UC3
, and output
will most likely has type CV_32FC3
, not just CV_32F
. And again, when you use cv::invert()
, you are looking at mathematical inverse, that is output * mat = identity_matrix
.
+(UIImage *)processInvertedImage:(UIImage *)image
cv::Mat mat;
UIImageToMat(image, mat); ///this is CV_8U from iPhone camera
if (mat.type() == CV_8UC3)
NSLog(@"mat type is CV_8UC3"); // mostlikely this
else if (mat.type() == CV_8UC4)
NSLog(@"mat type is CV_8UC4");
cv::Mat output;
mat.convertTo(output, CV_32F); ///cv::invert() requires CV_32F!! (apparently)
if (output.type() == CV_32FC3)
NSLog(@"output type is CV_32FC3"); // most likely this
// this is really bad naming, since you seem to use namespace cv somewhere,
// as CV_32F doesn't have cv:: prefix
cv::Mat invert;
cv::invert(output, invert); /// app crashes here, error message below
cv::Mat gray;
cv::cvtColor(invert, gray, CV_RGB2GRAY);
UIImage *binImg = MatToUIImage(gray);
return binImg;
Edit: If you need image processing inverse, then you can do something similar to what you had in last question:
+(UIImage *)processInvertedImage:(UIImage *)image
cv::Mat mat;
UIImageToMat(image, mat);
// convert to RGB
cv::Mat rgb
cv::cvtColor(mat, rgb, COLOR_RGBA2RGB);
// create mat of same size and type with values 255
cv::Mat dummy(rgb.size(), rgb.type(), cv::Scalar(255,255,255));
// three channels
cv::Mat rgb_invert = dummy ^ rgb;
cv::Mat gray;
cv::cvtColor(rgb, gray, COLOR_RGB2GRAY);
cv::Mat gray_invert = 255 ^ gray;
// depending what invert you would like
UIImage* binImg = MatToUIImage(rgb_invert);
return binImg;
Let me try to answer this one for good. type == 5 || type == 6
means you need to work with CV_32F
or CV_64F
. However, UIImage
usually has 4 channels. I bet your UIImageToMat
yields a mat of type CV_8UC3
. So mat
has type CV_8UC3
, and output
will most likely has type CV_32FC3
, not just CV_32F
. And again, when you use cv::invert()
, you are looking at mathematical inverse, that is output * mat = identity_matrix
.
+(UIImage *)processInvertedImage:(UIImage *)image
cv::Mat mat;
UIImageToMat(image, mat); ///this is CV_8U from iPhone camera
if (mat.type() == CV_8UC3)
NSLog(@"mat type is CV_8UC3"); // mostlikely this
else if (mat.type() == CV_8UC4)
NSLog(@"mat type is CV_8UC4");
cv::Mat output;
mat.convertTo(output, CV_32F); ///cv::invert() requires CV_32F!! (apparently)
if (output.type() == CV_32FC3)
NSLog(@"output type is CV_32FC3"); // most likely this
// this is really bad naming, since you seem to use namespace cv somewhere,
// as CV_32F doesn't have cv:: prefix
cv::Mat invert;
cv::invert(output, invert); /// app crashes here, error message below
cv::Mat gray;
cv::cvtColor(invert, gray, CV_RGB2GRAY);
UIImage *binImg = MatToUIImage(gray);
return binImg;
Edit: If you need image processing inverse, then you can do something similar to what you had in last question:
+(UIImage *)processInvertedImage:(UIImage *)image
cv::Mat mat;
UIImageToMat(image, mat);
// convert to RGB
cv::Mat rgb
cv::cvtColor(mat, rgb, COLOR_RGBA2RGB);
// create mat of same size and type with values 255
cv::Mat dummy(rgb.size(), rgb.type(), cv::Scalar(255,255,255));
// three channels
cv::Mat rgb_invert = dummy ^ rgb;
cv::Mat gray;
cv::cvtColor(rgb, gray, COLOR_RGB2GRAY);
cv::Mat gray_invert = 255 ^ gray;
// depending what invert you would like
UIImage* binImg = MatToUIImage(rgb_invert);
return binImg;
edited Nov 9 at 2:46
answered Nov 9 at 2:16
Quang Hoang
1,5121913
1,5121913
ok, ran it. is is is CV_8UC4. crashed before it came to the CV_32F question
– kangarooChris
Nov 9 at 2:25
1
I believed you when you said it crashed at theinvert
function :D. You can go around bycv::cvtColor(mat, gray, COLOR_RGBA2GRAY)
andgray.convertTo(output, CV_32F)
. But then,invert
will beCV_32F
, notRGB
, i.e.CV_8UC3
. Anyway, I am still not sure why you need mathematical inverse of an image.
– Quang Hoang
Nov 9 at 2:28
I actually don't need mathematical inverse . I misunderstood this. all I want is to change the dark background to light background, which I need for shape recognition. which function do you suggest
– kangarooChris
Nov 9 at 2:31
ran it as per above suggestion and error message has changed now to : libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.2) /Volumes/build-storage/build/3_4_iOS-mac/opencv/modules/core/src/lapack.cpp:863: error: (-215:Assertion failed) m == n in function 'invert'
– kangarooChris
Nov 9 at 2:39
1
That's because only square matrices have mathematical inverses. See edit for image processing inverse.
– Quang Hoang
Nov 9 at 2:47
|
show 1 more comment
ok, ran it. is is is CV_8UC4. crashed before it came to the CV_32F question
– kangarooChris
Nov 9 at 2:25
1
I believed you when you said it crashed at theinvert
function :D. You can go around bycv::cvtColor(mat, gray, COLOR_RGBA2GRAY)
andgray.convertTo(output, CV_32F)
. But then,invert
will beCV_32F
, notRGB
, i.e.CV_8UC3
. Anyway, I am still not sure why you need mathematical inverse of an image.
– Quang Hoang
Nov 9 at 2:28
I actually don't need mathematical inverse . I misunderstood this. all I want is to change the dark background to light background, which I need for shape recognition. which function do you suggest
– kangarooChris
Nov 9 at 2:31
ran it as per above suggestion and error message has changed now to : libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.2) /Volumes/build-storage/build/3_4_iOS-mac/opencv/modules/core/src/lapack.cpp:863: error: (-215:Assertion failed) m == n in function 'invert'
– kangarooChris
Nov 9 at 2:39
1
That's because only square matrices have mathematical inverses. See edit for image processing inverse.
– Quang Hoang
Nov 9 at 2:47
ok, ran it. is is is CV_8UC4. crashed before it came to the CV_32F question
– kangarooChris
Nov 9 at 2:25
ok, ran it. is is is CV_8UC4. crashed before it came to the CV_32F question
– kangarooChris
Nov 9 at 2:25
1
1
I believed you when you said it crashed at the
invert
function :D. You can go around by cv::cvtColor(mat, gray, COLOR_RGBA2GRAY)
and gray.convertTo(output, CV_32F)
. But then, invert
will be CV_32F
, not RGB
, i.e. CV_8UC3
. Anyway, I am still not sure why you need mathematical inverse of an image.– Quang Hoang
Nov 9 at 2:28
I believed you when you said it crashed at the
invert
function :D. You can go around by cv::cvtColor(mat, gray, COLOR_RGBA2GRAY)
and gray.convertTo(output, CV_32F)
. But then, invert
will be CV_32F
, not RGB
, i.e. CV_8UC3
. Anyway, I am still not sure why you need mathematical inverse of an image.– Quang Hoang
Nov 9 at 2:28
I actually don't need mathematical inverse . I misunderstood this. all I want is to change the dark background to light background, which I need for shape recognition. which function do you suggest
– kangarooChris
Nov 9 at 2:31
I actually don't need mathematical inverse . I misunderstood this. all I want is to change the dark background to light background, which I need for shape recognition. which function do you suggest
– kangarooChris
Nov 9 at 2:31
ran it as per above suggestion and error message has changed now to : libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.2) /Volumes/build-storage/build/3_4_iOS-mac/opencv/modules/core/src/lapack.cpp:863: error: (-215:Assertion failed) m == n in function 'invert'
– kangarooChris
Nov 9 at 2:39
ran it as per above suggestion and error message has changed now to : libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.2) /Volumes/build-storage/build/3_4_iOS-mac/opencv/modules/core/src/lapack.cpp:863: error: (-215:Assertion failed) m == n in function 'invert'
– kangarooChris
Nov 9 at 2:39
1
1
That's because only square matrices have mathematical inverses. See edit for image processing inverse.
– Quang Hoang
Nov 9 at 2:47
That's because only square matrices have mathematical inverses. See edit for image processing inverse.
– Quang Hoang
Nov 9 at 2:47
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53218402%2fwhy-is-my-app-crashing-when-i-try-to-invert-a-uiimage-in-opencv%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Not a duplicate, but very similar question here. You have exactly his problem. See my answer and comment for details.
– Quang Hoang
Nov 9 at 1:36
Hi Quang, yes, that was my question yesterday. Just needed to ask it again since after I introduced your suggestions it actually still does not work.
– kangarooChris
Nov 9 at 2:00
you suggested the conversion to CV_32F, but still crashing with exactly the same error message, so there must be something else going on here.
– kangarooChris
Nov 9 at 2:02
wouldn't it be better to convert to gray scale and then do the invert function?? with invert requiring CV_23F is that then possible at all?
– kangarooChris
Nov 9 at 2:04
I didn't notice the same poster. I am adding an answer here.
– Quang Hoang
Nov 9 at 2:05