Exception at memory location with opencv
I'm new opencv c++ developer. I applied the SLIC superpixel so I have Mat:labels contain the ID of each pixel, I applied SPLIT on the image to get the Green channel and then I'm looking to change the value of specific pixels who have the ID=150 ( each pixel =! of 150 must is converted to black pixel). after debug I got this bug and this window:
Exception thrown at 0x00007FFB63A0A388 : Microsoft C++ exception: cv::Exception at memory location 0x0000001496AFE290.
Unhandled exception at 0x00007FFB63A0A388 : Microsoft C++ exception: cv::Exception at memory location 0x0000001496AFE290.
Here's my code
int main()
{
Mat labels;
Mat RGB[3], HSV[3],S_HSV,image3;
vector<double> STD, generale_mean;
Mat image, Red, Green, Blue, image2,mask,Gray;
int region_number;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
image = imread("D:\mémoire\eye.png", CV_LOAD_IMAGE_COLOR);
//applying the superpixel
Ptr<cv::ximgproc::SuperpixelSLIC> slic = cv::ximgproc::createSuperpixelSLIC(image, 100,50, 0.01);
slic->iterate(10);
if (true)
slic->enforceLabelConnectivity(50);
slic->getLabelContourMask(mask, true);
image.setTo((0, 0, 255), mask);
slic->getLabels(labels);
region_number = slic->getNumberOfSuperpixels();
cv::cvtColor(image, image, CV_BGR2RGB);
cv::cvtColor(image, Gray,CV_RGB2GRAY);
split(image, RGB);
Red.push_back(RGB[0]);
Green.push_back(RGB[1]);
Blue.push_back(RGB[2]);
int f = 150;
Mat Green1 = Green.clone();
int Y =0;
for (int j = 0; j < Green1.rows; j++) {
for (int i = 0; i < Green1.cols; i++) {
double N = labels.at<double>(Point(i, j));
if (N =! f)
Green1.at<double>(Point(i, j)) = 00000;
}
}
cv::imshow("green", Green1);
waitKey(0); // Wait for a keystroke in the window
return 0;
}
c++ visual-studio opencv
|
show 4 more comments
I'm new opencv c++ developer. I applied the SLIC superpixel so I have Mat:labels contain the ID of each pixel, I applied SPLIT on the image to get the Green channel and then I'm looking to change the value of specific pixels who have the ID=150 ( each pixel =! of 150 must is converted to black pixel). after debug I got this bug and this window:
Exception thrown at 0x00007FFB63A0A388 : Microsoft C++ exception: cv::Exception at memory location 0x0000001496AFE290.
Unhandled exception at 0x00007FFB63A0A388 : Microsoft C++ exception: cv::Exception at memory location 0x0000001496AFE290.
Here's my code
int main()
{
Mat labels;
Mat RGB[3], HSV[3],S_HSV,image3;
vector<double> STD, generale_mean;
Mat image, Red, Green, Blue, image2,mask,Gray;
int region_number;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
image = imread("D:\mémoire\eye.png", CV_LOAD_IMAGE_COLOR);
//applying the superpixel
Ptr<cv::ximgproc::SuperpixelSLIC> slic = cv::ximgproc::createSuperpixelSLIC(image, 100,50, 0.01);
slic->iterate(10);
if (true)
slic->enforceLabelConnectivity(50);
slic->getLabelContourMask(mask, true);
image.setTo((0, 0, 255), mask);
slic->getLabels(labels);
region_number = slic->getNumberOfSuperpixels();
cv::cvtColor(image, image, CV_BGR2RGB);
cv::cvtColor(image, Gray,CV_RGB2GRAY);
split(image, RGB);
Red.push_back(RGB[0]);
Green.push_back(RGB[1]);
Blue.push_back(RGB[2]);
int f = 150;
Mat Green1 = Green.clone();
int Y =0;
for (int j = 0; j < Green1.rows; j++) {
for (int i = 0; i < Green1.cols; i++) {
double N = labels.at<double>(Point(i, j));
if (N =! f)
Green1.at<double>(Point(i, j)) = 00000;
}
}
cv::imshow("green", Green1);
waitKey(0); // Wait for a keystroke in the window
return 0;
}
c++ visual-studio opencv
1
Have you debugged this? This is not enough for us to help you more than this.
– Matthieu Brucher
Nov 26 '18 at 10:50
1
i'll update my post and put all the code
– ben mbarek Manef
Nov 26 '18 at 10:53
1
What is the exception that was thrown? The error message basically just says that OpenCV threw an exception, but it does not show the details of the opencv exception. For example, a call stack would really help.
– Max Langhof
Nov 26 '18 at 11:36
1
how can i show the exception ?!
– ben mbarek Manef
Nov 26 '18 at 12:00
2
The error is in this lineGreen1.at<double>(Point(i, j)) = 00000;
first is an uchar not a double, and you can do without point like thisGreen1.at<uchar>(j,i) = 0;
note that at receives row, column in comparison of point that receives x,y
– api55
Nov 26 '18 at 12:03
|
show 4 more comments
I'm new opencv c++ developer. I applied the SLIC superpixel so I have Mat:labels contain the ID of each pixel, I applied SPLIT on the image to get the Green channel and then I'm looking to change the value of specific pixels who have the ID=150 ( each pixel =! of 150 must is converted to black pixel). after debug I got this bug and this window:
Exception thrown at 0x00007FFB63A0A388 : Microsoft C++ exception: cv::Exception at memory location 0x0000001496AFE290.
Unhandled exception at 0x00007FFB63A0A388 : Microsoft C++ exception: cv::Exception at memory location 0x0000001496AFE290.
Here's my code
int main()
{
Mat labels;
Mat RGB[3], HSV[3],S_HSV,image3;
vector<double> STD, generale_mean;
Mat image, Red, Green, Blue, image2,mask,Gray;
int region_number;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
image = imread("D:\mémoire\eye.png", CV_LOAD_IMAGE_COLOR);
//applying the superpixel
Ptr<cv::ximgproc::SuperpixelSLIC> slic = cv::ximgproc::createSuperpixelSLIC(image, 100,50, 0.01);
slic->iterate(10);
if (true)
slic->enforceLabelConnectivity(50);
slic->getLabelContourMask(mask, true);
image.setTo((0, 0, 255), mask);
slic->getLabels(labels);
region_number = slic->getNumberOfSuperpixels();
cv::cvtColor(image, image, CV_BGR2RGB);
cv::cvtColor(image, Gray,CV_RGB2GRAY);
split(image, RGB);
Red.push_back(RGB[0]);
Green.push_back(RGB[1]);
Blue.push_back(RGB[2]);
int f = 150;
Mat Green1 = Green.clone();
int Y =0;
for (int j = 0; j < Green1.rows; j++) {
for (int i = 0; i < Green1.cols; i++) {
double N = labels.at<double>(Point(i, j));
if (N =! f)
Green1.at<double>(Point(i, j)) = 00000;
}
}
cv::imshow("green", Green1);
waitKey(0); // Wait for a keystroke in the window
return 0;
}
c++ visual-studio opencv
I'm new opencv c++ developer. I applied the SLIC superpixel so I have Mat:labels contain the ID of each pixel, I applied SPLIT on the image to get the Green channel and then I'm looking to change the value of specific pixels who have the ID=150 ( each pixel =! of 150 must is converted to black pixel). after debug I got this bug and this window:
Exception thrown at 0x00007FFB63A0A388 : Microsoft C++ exception: cv::Exception at memory location 0x0000001496AFE290.
Unhandled exception at 0x00007FFB63A0A388 : Microsoft C++ exception: cv::Exception at memory location 0x0000001496AFE290.
Here's my code
int main()
{
Mat labels;
Mat RGB[3], HSV[3],S_HSV,image3;
vector<double> STD, generale_mean;
Mat image, Red, Green, Blue, image2,mask,Gray;
int region_number;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
image = imread("D:\mémoire\eye.png", CV_LOAD_IMAGE_COLOR);
//applying the superpixel
Ptr<cv::ximgproc::SuperpixelSLIC> slic = cv::ximgproc::createSuperpixelSLIC(image, 100,50, 0.01);
slic->iterate(10);
if (true)
slic->enforceLabelConnectivity(50);
slic->getLabelContourMask(mask, true);
image.setTo((0, 0, 255), mask);
slic->getLabels(labels);
region_number = slic->getNumberOfSuperpixels();
cv::cvtColor(image, image, CV_BGR2RGB);
cv::cvtColor(image, Gray,CV_RGB2GRAY);
split(image, RGB);
Red.push_back(RGB[0]);
Green.push_back(RGB[1]);
Blue.push_back(RGB[2]);
int f = 150;
Mat Green1 = Green.clone();
int Y =0;
for (int j = 0; j < Green1.rows; j++) {
for (int i = 0; i < Green1.cols; i++) {
double N = labels.at<double>(Point(i, j));
if (N =! f)
Green1.at<double>(Point(i, j)) = 00000;
}
}
cv::imshow("green", Green1);
waitKey(0); // Wait for a keystroke in the window
return 0;
}
c++ visual-studio opencv
c++ visual-studio opencv
edited Nov 26 '18 at 11:00
JBL
9,74333767
9,74333767
asked Nov 26 '18 at 10:49
ben mbarek Manefben mbarek Manef
256
256
1
Have you debugged this? This is not enough for us to help you more than this.
– Matthieu Brucher
Nov 26 '18 at 10:50
1
i'll update my post and put all the code
– ben mbarek Manef
Nov 26 '18 at 10:53
1
What is the exception that was thrown? The error message basically just says that OpenCV threw an exception, but it does not show the details of the opencv exception. For example, a call stack would really help.
– Max Langhof
Nov 26 '18 at 11:36
1
how can i show the exception ?!
– ben mbarek Manef
Nov 26 '18 at 12:00
2
The error is in this lineGreen1.at<double>(Point(i, j)) = 00000;
first is an uchar not a double, and you can do without point like thisGreen1.at<uchar>(j,i) = 0;
note that at receives row, column in comparison of point that receives x,y
– api55
Nov 26 '18 at 12:03
|
show 4 more comments
1
Have you debugged this? This is not enough for us to help you more than this.
– Matthieu Brucher
Nov 26 '18 at 10:50
1
i'll update my post and put all the code
– ben mbarek Manef
Nov 26 '18 at 10:53
1
What is the exception that was thrown? The error message basically just says that OpenCV threw an exception, but it does not show the details of the opencv exception. For example, a call stack would really help.
– Max Langhof
Nov 26 '18 at 11:36
1
how can i show the exception ?!
– ben mbarek Manef
Nov 26 '18 at 12:00
2
The error is in this lineGreen1.at<double>(Point(i, j)) = 00000;
first is an uchar not a double, and you can do without point like thisGreen1.at<uchar>(j,i) = 0;
note that at receives row, column in comparison of point that receives x,y
– api55
Nov 26 '18 at 12:03
1
1
Have you debugged this? This is not enough for us to help you more than this.
– Matthieu Brucher
Nov 26 '18 at 10:50
Have you debugged this? This is not enough for us to help you more than this.
– Matthieu Brucher
Nov 26 '18 at 10:50
1
1
i'll update my post and put all the code
– ben mbarek Manef
Nov 26 '18 at 10:53
i'll update my post and put all the code
– ben mbarek Manef
Nov 26 '18 at 10:53
1
1
What is the exception that was thrown? The error message basically just says that OpenCV threw an exception, but it does not show the details of the opencv exception. For example, a call stack would really help.
– Max Langhof
Nov 26 '18 at 11:36
What is the exception that was thrown? The error message basically just says that OpenCV threw an exception, but it does not show the details of the opencv exception. For example, a call stack would really help.
– Max Langhof
Nov 26 '18 at 11:36
1
1
how can i show the exception ?!
– ben mbarek Manef
Nov 26 '18 at 12:00
how can i show the exception ?!
– ben mbarek Manef
Nov 26 '18 at 12:00
2
2
The error is in this line
Green1.at<double>(Point(i, j)) = 00000;
first is an uchar not a double, and you can do without point like this Green1.at<uchar>(j,i) = 0;
note that at receives row, column in comparison of point that receives x,y– api55
Nov 26 '18 at 12:03
The error is in this line
Green1.at<double>(Point(i, j)) = 00000;
first is an uchar not a double, and you can do without point like this Green1.at<uchar>(j,i) = 0;
note that at receives row, column in comparison of point that receives x,y– api55
Nov 26 '18 at 12:03
|
show 4 more comments
1 Answer
1
active
oldest
votes
You have problems with the types of the image. When you load an image in OpenCV using:
image = imread(filename, CV_LOAD_IMAGE_COLOR);
it will be an image of type CV8UC3. This means, that it will have 3 channels (the C3 part) and that each pixel value for each channel is of type unsigned int of 8 bits. In C++ you can use uchar for it. Then when you use the at function, you need to use a type that can hold the information correctly... that is in this case uchar. In you code you have:
Green1.at<double>(Point(i, j)) = 00000;
which should be:
Green1.at<uchar>(j,i) = 0;
Note that also Point(i,j)
is not needed and can be replaced by j,i
.
The .at<type>(row, column)
function is more or less equivalent to do:
Mat test;
type* data = reinterpret_cast<type*>(test.data);
data[row][column];
You also have a problem in:
double N = labels.at<double>(Point(i, j));
but labels it is assign by
slic->getLabels(labels);
which gives a mat of type CV_32SC1 -> that means, 1 Channel and 32 bits signed integer, or in C++, int.
Then this should be :
int N = labels.at<int>(j,i);
Finally:
this
Red.push_back(RGB[0]);
Green.push_back(RGB[1]);
Blue.push_back(RGB[2]);
should be:
Red = RGB[0];
Green = RGB[1];
Blue = RGB[2];
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
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%2f53479495%2fexception-at-memory-location-with-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
You have problems with the types of the image. When you load an image in OpenCV using:
image = imread(filename, CV_LOAD_IMAGE_COLOR);
it will be an image of type CV8UC3. This means, that it will have 3 channels (the C3 part) and that each pixel value for each channel is of type unsigned int of 8 bits. In C++ you can use uchar for it. Then when you use the at function, you need to use a type that can hold the information correctly... that is in this case uchar. In you code you have:
Green1.at<double>(Point(i, j)) = 00000;
which should be:
Green1.at<uchar>(j,i) = 0;
Note that also Point(i,j)
is not needed and can be replaced by j,i
.
The .at<type>(row, column)
function is more or less equivalent to do:
Mat test;
type* data = reinterpret_cast<type*>(test.data);
data[row][column];
You also have a problem in:
double N = labels.at<double>(Point(i, j));
but labels it is assign by
slic->getLabels(labels);
which gives a mat of type CV_32SC1 -> that means, 1 Channel and 32 bits signed integer, or in C++, int.
Then this should be :
int N = labels.at<int>(j,i);
Finally:
this
Red.push_back(RGB[0]);
Green.push_back(RGB[1]);
Blue.push_back(RGB[2]);
should be:
Red = RGB[0];
Green = RGB[1];
Blue = RGB[2];
add a comment |
You have problems with the types of the image. When you load an image in OpenCV using:
image = imread(filename, CV_LOAD_IMAGE_COLOR);
it will be an image of type CV8UC3. This means, that it will have 3 channels (the C3 part) and that each pixel value for each channel is of type unsigned int of 8 bits. In C++ you can use uchar for it. Then when you use the at function, you need to use a type that can hold the information correctly... that is in this case uchar. In you code you have:
Green1.at<double>(Point(i, j)) = 00000;
which should be:
Green1.at<uchar>(j,i) = 0;
Note that also Point(i,j)
is not needed and can be replaced by j,i
.
The .at<type>(row, column)
function is more or less equivalent to do:
Mat test;
type* data = reinterpret_cast<type*>(test.data);
data[row][column];
You also have a problem in:
double N = labels.at<double>(Point(i, j));
but labels it is assign by
slic->getLabels(labels);
which gives a mat of type CV_32SC1 -> that means, 1 Channel and 32 bits signed integer, or in C++, int.
Then this should be :
int N = labels.at<int>(j,i);
Finally:
this
Red.push_back(RGB[0]);
Green.push_back(RGB[1]);
Blue.push_back(RGB[2]);
should be:
Red = RGB[0];
Green = RGB[1];
Blue = RGB[2];
add a comment |
You have problems with the types of the image. When you load an image in OpenCV using:
image = imread(filename, CV_LOAD_IMAGE_COLOR);
it will be an image of type CV8UC3. This means, that it will have 3 channels (the C3 part) and that each pixel value for each channel is of type unsigned int of 8 bits. In C++ you can use uchar for it. Then when you use the at function, you need to use a type that can hold the information correctly... that is in this case uchar. In you code you have:
Green1.at<double>(Point(i, j)) = 00000;
which should be:
Green1.at<uchar>(j,i) = 0;
Note that also Point(i,j)
is not needed and can be replaced by j,i
.
The .at<type>(row, column)
function is more or less equivalent to do:
Mat test;
type* data = reinterpret_cast<type*>(test.data);
data[row][column];
You also have a problem in:
double N = labels.at<double>(Point(i, j));
but labels it is assign by
slic->getLabels(labels);
which gives a mat of type CV_32SC1 -> that means, 1 Channel and 32 bits signed integer, or in C++, int.
Then this should be :
int N = labels.at<int>(j,i);
Finally:
this
Red.push_back(RGB[0]);
Green.push_back(RGB[1]);
Blue.push_back(RGB[2]);
should be:
Red = RGB[0];
Green = RGB[1];
Blue = RGB[2];
You have problems with the types of the image. When you load an image in OpenCV using:
image = imread(filename, CV_LOAD_IMAGE_COLOR);
it will be an image of type CV8UC3. This means, that it will have 3 channels (the C3 part) and that each pixel value for each channel is of type unsigned int of 8 bits. In C++ you can use uchar for it. Then when you use the at function, you need to use a type that can hold the information correctly... that is in this case uchar. In you code you have:
Green1.at<double>(Point(i, j)) = 00000;
which should be:
Green1.at<uchar>(j,i) = 0;
Note that also Point(i,j)
is not needed and can be replaced by j,i
.
The .at<type>(row, column)
function is more or less equivalent to do:
Mat test;
type* data = reinterpret_cast<type*>(test.data);
data[row][column];
You also have a problem in:
double N = labels.at<double>(Point(i, j));
but labels it is assign by
slic->getLabels(labels);
which gives a mat of type CV_32SC1 -> that means, 1 Channel and 32 bits signed integer, or in C++, int.
Then this should be :
int N = labels.at<int>(j,i);
Finally:
this
Red.push_back(RGB[0]);
Green.push_back(RGB[1]);
Blue.push_back(RGB[2]);
should be:
Red = RGB[0];
Green = RGB[1];
Blue = RGB[2];
answered Nov 26 '18 at 12:25
api55api55
6,86532543
6,86532543
add a comment |
add a 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.
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%2f53479495%2fexception-at-memory-location-with-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
1
Have you debugged this? This is not enough for us to help you more than this.
– Matthieu Brucher
Nov 26 '18 at 10:50
1
i'll update my post and put all the code
– ben mbarek Manef
Nov 26 '18 at 10:53
1
What is the exception that was thrown? The error message basically just says that OpenCV threw an exception, but it does not show the details of the opencv exception. For example, a call stack would really help.
– Max Langhof
Nov 26 '18 at 11:36
1
how can i show the exception ?!
– ben mbarek Manef
Nov 26 '18 at 12:00
2
The error is in this line
Green1.at<double>(Point(i, j)) = 00000;
first is an uchar not a double, and you can do without point like thisGreen1.at<uchar>(j,i) = 0;
note that at receives row, column in comparison of point that receives x,y– api55
Nov 26 '18 at 12:03