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.
opencv image-processing
add a comment |
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.
opencv image-processing
"inverted = !gray;" please read the doc next time
– Miki
13 hours ago
add a comment |
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.
opencv image-processing
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
opencv image-processing
asked 14 hours ago
kangarooChris
193114
193114
"inverted = !gray;" please read the doc next time
– Miki
13 hours ago
add a comment |
"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
add a comment |
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.
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
add a 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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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
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
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
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
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
"inverted = !gray;" please read the doc next time
– Miki
13 hours ago