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?










share|improve this question





















  • 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














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?










share|improve this question





















  • 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












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?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
















  • 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












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;






share|improve this answer






















  • 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 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










  • 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










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















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

























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;






share|improve this answer






















  • 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 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










  • 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














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;






share|improve this answer






















  • 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 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










  • 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












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;






share|improve this answer














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;







share|improve this answer














share|improve this answer



share|improve this answer








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 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










  • 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






  • 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 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

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế