Why do I have an error message when inverting an image in openCV?











up vote
0
down vote

favorite












I am processing a UIImage for contour creation and in that process I am firstly inverting it, then making it gray. Here is the code:



+(UIImage *)processInvertedImage:(UIImage *)image {

cv::Mat mat;
UIImageToMat(image, mat);

cv::Mat gray;
cv::cvtColor(mat, gray, CV_RGB2GRAY);

cv::Mat inverted;
cv::invert(gray, inverted); //// here it crashes

UIImage *binImg = MatToUIImage(inverted);

return binImg;


}



This is the 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'



(lldb)



Why can't I use the invert methode? I tried to invert before converting to gray, but that did not make a difference.










share|improve this question






















  • "inverted = !gray;" please read the doc next time
    – Miki
    13 hours ago

















up vote
0
down vote

favorite












I am processing a UIImage for contour creation and in that process I am firstly inverting it, then making it gray. Here is the code:



+(UIImage *)processInvertedImage:(UIImage *)image {

cv::Mat mat;
UIImageToMat(image, mat);

cv::Mat gray;
cv::cvtColor(mat, gray, CV_RGB2GRAY);

cv::Mat inverted;
cv::invert(gray, inverted); //// here it crashes

UIImage *binImg = MatToUIImage(inverted);

return binImg;


}



This is the 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'



(lldb)



Why can't I use the invert methode? I tried to invert before converting to gray, but that did not make a difference.










share|improve this question






















  • "inverted = !gray;" please read the doc next time
    – Miki
    13 hours ago















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am processing a UIImage for contour creation and in that process I am firstly inverting it, then making it gray. Here is the code:



+(UIImage *)processInvertedImage:(UIImage *)image {

cv::Mat mat;
UIImageToMat(image, mat);

cv::Mat gray;
cv::cvtColor(mat, gray, CV_RGB2GRAY);

cv::Mat inverted;
cv::invert(gray, inverted); //// here it crashes

UIImage *binImg = MatToUIImage(inverted);

return binImg;


}



This is the 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'



(lldb)



Why can't I use the invert methode? I tried to invert before converting to gray, but that did not make a difference.










share|improve this question













I am processing a UIImage for contour creation and in that process I am firstly inverting it, then making it gray. Here is the code:



+(UIImage *)processInvertedImage:(UIImage *)image {

cv::Mat mat;
UIImageToMat(image, mat);

cv::Mat gray;
cv::cvtColor(mat, gray, CV_RGB2GRAY);

cv::Mat inverted;
cv::invert(gray, inverted); //// here it crashes

UIImage *binImg = MatToUIImage(inverted);

return binImg;


}



This is the 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'



(lldb)



Why can't I use the invert methode? I tried to invert before converting to gray, but that did not make a difference.







opencv image-processing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 14 hours ago









kangarooChris

193114




193114












  • "inverted = !gray;" please read the doc next time
    – Miki
    13 hours ago




















  • "inverted = !gray;" please read the doc next time
    – Miki
    13 hours ago


















"inverted = !gray;" please read the doc next time
– Miki
13 hours ago






"inverted = !gray;" please read the doc next time
– Miki
13 hours ago














1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










From the document : cv::invert() requires CV_32F or CV_64F as type, not CV_8U in your case. Also, just want to make sure you want the right inverse, cv::inverse() is the mathematical inverse, not image processing inverse.






share|improve this answer





















  • instead of white - black I want the picture to convert to black-white, so, I guess invert() is correct, right? I did try to do the invert() before processing to gray. isn't a UIImage CV_32F (I am taking this directly from the camera).
    – kangarooChris
    13 hours ago










  • No, they are typically 'CV_8U'. And this method is not what you want. You are either looking for 'inverted=255-gray' or 'inverted=255^gray'.
    – Quang Hoang
    13 hours ago










  • thanks, that was it, great
    – kangarooChris
    12 hours ago











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%2f53203280%2fwhy-do-i-have-an-error-message-when-inverting-an-image-in-opencv%23new-answer', 'question_page');
}
);

Post as a guest
































1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










From the document : cv::invert() requires CV_32F or CV_64F as type, not CV_8U in your case. Also, just want to make sure you want the right inverse, cv::inverse() is the mathematical inverse, not image processing inverse.






share|improve this answer





















  • instead of white - black I want the picture to convert to black-white, so, I guess invert() is correct, right? I did try to do the invert() before processing to gray. isn't a UIImage CV_32F (I am taking this directly from the camera).
    – kangarooChris
    13 hours ago










  • No, they are typically 'CV_8U'. And this method is not what you want. You are either looking for 'inverted=255-gray' or 'inverted=255^gray'.
    – Quang Hoang
    13 hours ago










  • thanks, that was it, great
    – kangarooChris
    12 hours ago















up vote
0
down vote



accepted










From the document : cv::invert() requires CV_32F or CV_64F as type, not CV_8U in your case. Also, just want to make sure you want the right inverse, cv::inverse() is the mathematical inverse, not image processing inverse.






share|improve this answer





















  • instead of white - black I want the picture to convert to black-white, so, I guess invert() is correct, right? I did try to do the invert() before processing to gray. isn't a UIImage CV_32F (I am taking this directly from the camera).
    – kangarooChris
    13 hours ago










  • No, they are typically 'CV_8U'. And this method is not what you want. You are either looking for 'inverted=255-gray' or 'inverted=255^gray'.
    – Quang Hoang
    13 hours ago










  • thanks, that was it, great
    – kangarooChris
    12 hours ago













up vote
0
down vote



accepted







up vote
0
down vote



accepted






From the document : cv::invert() requires CV_32F or CV_64F as type, not CV_8U in your case. Also, just want to make sure you want the right inverse, cv::inverse() is the mathematical inverse, not image processing inverse.






share|improve this answer












From the document : cv::invert() requires CV_32F or CV_64F as type, not CV_8U in your case. Also, just want to make sure you want the right inverse, cv::inverse() is the mathematical inverse, not image processing inverse.







share|improve this answer












share|improve this answer



share|improve this answer










answered 13 hours ago









Quang Hoang

1,487813




1,487813












  • instead of white - black I want the picture to convert to black-white, so, I guess invert() is correct, right? I did try to do the invert() before processing to gray. isn't a UIImage CV_32F (I am taking this directly from the camera).
    – kangarooChris
    13 hours ago










  • No, they are typically 'CV_8U'. And this method is not what you want. You are either looking for 'inverted=255-gray' or 'inverted=255^gray'.
    – Quang Hoang
    13 hours ago










  • thanks, that was it, great
    – kangarooChris
    12 hours ago


















  • instead of white - black I want the picture to convert to black-white, so, I guess invert() is correct, right? I did try to do the invert() before processing to gray. isn't a UIImage CV_32F (I am taking this directly from the camera).
    – kangarooChris
    13 hours ago










  • No, they are typically 'CV_8U'. And this method is not what you want. You are either looking for 'inverted=255-gray' or 'inverted=255^gray'.
    – Quang Hoang
    13 hours ago










  • thanks, that was it, great
    – kangarooChris
    12 hours ago
















instead of white - black I want the picture to convert to black-white, so, I guess invert() is correct, right? I did try to do the invert() before processing to gray. isn't a UIImage CV_32F (I am taking this directly from the camera).
– kangarooChris
13 hours ago




instead of white - black I want the picture to convert to black-white, so, I guess invert() is correct, right? I did try to do the invert() before processing to gray. isn't a UIImage CV_32F (I am taking this directly from the camera).
– kangarooChris
13 hours ago












No, they are typically 'CV_8U'. And this method is not what you want. You are either looking for 'inverted=255-gray' or 'inverted=255^gray'.
– Quang Hoang
13 hours ago




No, they are typically 'CV_8U'. And this method is not what you want. You are either looking for 'inverted=255-gray' or 'inverted=255^gray'.
– Quang Hoang
13 hours ago












thanks, that was it, great
– kangarooChris
12 hours ago




thanks, that was it, great
– kangarooChris
12 hours ago


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203280%2fwhy-do-i-have-an-error-message-when-inverting-an-image-in-opencv%23new-answer', 'question_page');
}
);

Post as a guest




















































































Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff