Issues using cvtColor with Mat of CV_8U
I am using a black/white camera for a research project and am updating existing code from a previous individual. In multiple attempts to run the following program, I continue to hit a breakpoint within the line containing cvtColor
.
pin_ptr<System::Byte> pinPtrArray;
pinPtrArray = &e->GetImageData->dataRawPixels1Byte[0];
Mat im(e->Width,e->Height, CV_8U, pinPtrArray);
Mat color, thresh;
cvtColor(im, color, COLOR_BGR2GRAY);
threshold(color, thresh, 110, 255, THRESH_BINARY);
imshow("thresh", thresh);
waitKey(20);
This portion is within a continuous 'for' loop taking images from an external camera, not the computer's webcam. If anyone could explain why I might be hitting this roadblock or notices incorrect in how I have initialized objects, that would be greatly appreciated. Thx!
opencv c++-cli
add a comment |
I am using a black/white camera for a research project and am updating existing code from a previous individual. In multiple attempts to run the following program, I continue to hit a breakpoint within the line containing cvtColor
.
pin_ptr<System::Byte> pinPtrArray;
pinPtrArray = &e->GetImageData->dataRawPixels1Byte[0];
Mat im(e->Width,e->Height, CV_8U, pinPtrArray);
Mat color, thresh;
cvtColor(im, color, COLOR_BGR2GRAY);
threshold(color, thresh, 110, 255, THRESH_BINARY);
imshow("thresh", thresh);
waitKey(20);
This portion is within a continuous 'for' loop taking images from an external camera, not the computer's webcam. If anyone could explain why I might be hitting this roadblock or notices incorrect in how I have initialized objects, that would be greatly appreciated. Thx!
opencv c++-cli
You've got a BW camera, and create a single channelMat
from the data you received. So, why is the first thing you do with it an attempt to convert it from BGR to grayscale? (Also, it's rather puzzling why you'd call the variable to hold the result of such operation "color")
– Dan Mašek
Nov 14 '18 at 21:05
@DanMašek, I probably should have excluded that from the sample and should have restated forthreshold
. I am having the same issue when removingcvtColor
with the same error of "System.AccessViolationException: 'Attempted to read or write protected memory'". I believe it most likely has to do with how I am originally formatting my Mat container.
– NewToLiving
Nov 14 '18 at 21:17
In that case it would seem to be related to youre
object. Hard to say without a lot more details. I suggest you edit your question and add relevant details (such as the specific error you receive, since that's quite significant).
– Dan Mašek
Nov 14 '18 at 21:23
1
if there are 3*width*height elements in pinPtrArray then choose Mat im(e->Width,e->Height, CV_8UC3, pinPtrArray); to signalize it is a color image in the beginning. If there is only one channel you can't convert BGR2GRAY
– Micka
Nov 14 '18 at 22:01
add a comment |
I am using a black/white camera for a research project and am updating existing code from a previous individual. In multiple attempts to run the following program, I continue to hit a breakpoint within the line containing cvtColor
.
pin_ptr<System::Byte> pinPtrArray;
pinPtrArray = &e->GetImageData->dataRawPixels1Byte[0];
Mat im(e->Width,e->Height, CV_8U, pinPtrArray);
Mat color, thresh;
cvtColor(im, color, COLOR_BGR2GRAY);
threshold(color, thresh, 110, 255, THRESH_BINARY);
imshow("thresh", thresh);
waitKey(20);
This portion is within a continuous 'for' loop taking images from an external camera, not the computer's webcam. If anyone could explain why I might be hitting this roadblock or notices incorrect in how I have initialized objects, that would be greatly appreciated. Thx!
opencv c++-cli
I am using a black/white camera for a research project and am updating existing code from a previous individual. In multiple attempts to run the following program, I continue to hit a breakpoint within the line containing cvtColor
.
pin_ptr<System::Byte> pinPtrArray;
pinPtrArray = &e->GetImageData->dataRawPixels1Byte[0];
Mat im(e->Width,e->Height, CV_8U, pinPtrArray);
Mat color, thresh;
cvtColor(im, color, COLOR_BGR2GRAY);
threshold(color, thresh, 110, 255, THRESH_BINARY);
imshow("thresh", thresh);
waitKey(20);
This portion is within a continuous 'for' loop taking images from an external camera, not the computer's webcam. If anyone could explain why I might be hitting this roadblock or notices incorrect in how I have initialized objects, that would be greatly appreciated. Thx!
opencv c++-cli
opencv c++-cli
asked Nov 14 '18 at 19:53
NewToLivingNewToLiving
184
184
You've got a BW camera, and create a single channelMat
from the data you received. So, why is the first thing you do with it an attempt to convert it from BGR to grayscale? (Also, it's rather puzzling why you'd call the variable to hold the result of such operation "color")
– Dan Mašek
Nov 14 '18 at 21:05
@DanMašek, I probably should have excluded that from the sample and should have restated forthreshold
. I am having the same issue when removingcvtColor
with the same error of "System.AccessViolationException: 'Attempted to read or write protected memory'". I believe it most likely has to do with how I am originally formatting my Mat container.
– NewToLiving
Nov 14 '18 at 21:17
In that case it would seem to be related to youre
object. Hard to say without a lot more details. I suggest you edit your question and add relevant details (such as the specific error you receive, since that's quite significant).
– Dan Mašek
Nov 14 '18 at 21:23
1
if there are 3*width*height elements in pinPtrArray then choose Mat im(e->Width,e->Height, CV_8UC3, pinPtrArray); to signalize it is a color image in the beginning. If there is only one channel you can't convert BGR2GRAY
– Micka
Nov 14 '18 at 22:01
add a comment |
You've got a BW camera, and create a single channelMat
from the data you received. So, why is the first thing you do with it an attempt to convert it from BGR to grayscale? (Also, it's rather puzzling why you'd call the variable to hold the result of such operation "color")
– Dan Mašek
Nov 14 '18 at 21:05
@DanMašek, I probably should have excluded that from the sample and should have restated forthreshold
. I am having the same issue when removingcvtColor
with the same error of "System.AccessViolationException: 'Attempted to read or write protected memory'". I believe it most likely has to do with how I am originally formatting my Mat container.
– NewToLiving
Nov 14 '18 at 21:17
In that case it would seem to be related to youre
object. Hard to say without a lot more details. I suggest you edit your question and add relevant details (such as the specific error you receive, since that's quite significant).
– Dan Mašek
Nov 14 '18 at 21:23
1
if there are 3*width*height elements in pinPtrArray then choose Mat im(e->Width,e->Height, CV_8UC3, pinPtrArray); to signalize it is a color image in the beginning. If there is only one channel you can't convert BGR2GRAY
– Micka
Nov 14 '18 at 22:01
You've got a BW camera, and create a single channel
Mat
from the data you received. So, why is the first thing you do with it an attempt to convert it from BGR to grayscale? (Also, it's rather puzzling why you'd call the variable to hold the result of such operation "color")– Dan Mašek
Nov 14 '18 at 21:05
You've got a BW camera, and create a single channel
Mat
from the data you received. So, why is the first thing you do with it an attempt to convert it from BGR to grayscale? (Also, it's rather puzzling why you'd call the variable to hold the result of such operation "color")– Dan Mašek
Nov 14 '18 at 21:05
@DanMašek, I probably should have excluded that from the sample and should have restated for
threshold
. I am having the same issue when removing cvtColor
with the same error of "System.AccessViolationException: 'Attempted to read or write protected memory'". I believe it most likely has to do with how I am originally formatting my Mat container.– NewToLiving
Nov 14 '18 at 21:17
@DanMašek, I probably should have excluded that from the sample and should have restated for
threshold
. I am having the same issue when removing cvtColor
with the same error of "System.AccessViolationException: 'Attempted to read or write protected memory'". I believe it most likely has to do with how I am originally formatting my Mat container.– NewToLiving
Nov 14 '18 at 21:17
In that case it would seem to be related to your
e
object. Hard to say without a lot more details. I suggest you edit your question and add relevant details (such as the specific error you receive, since that's quite significant).– Dan Mašek
Nov 14 '18 at 21:23
In that case it would seem to be related to your
e
object. Hard to say without a lot more details. I suggest you edit your question and add relevant details (such as the specific error you receive, since that's quite significant).– Dan Mašek
Nov 14 '18 at 21:23
1
1
if there are 3*width*height elements in pinPtrArray then choose Mat im(e->Width,e->Height, CV_8UC3, pinPtrArray); to signalize it is a color image in the beginning. If there is only one channel you can't convert BGR2GRAY
– Micka
Nov 14 '18 at 22:01
if there are 3*width*height elements in pinPtrArray then choose Mat im(e->Width,e->Height, CV_8UC3, pinPtrArray); to signalize it is a color image in the beginning. If there is only one channel you can't convert BGR2GRAY
– Micka
Nov 14 '18 at 22:01
add a comment |
0
active
oldest
votes
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%2f53307823%2fissues-using-cvtcolor-with-mat-of-cv-8u%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53307823%2fissues-using-cvtcolor-with-mat-of-cv-8u%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
You've got a BW camera, and create a single channel
Mat
from the data you received. So, why is the first thing you do with it an attempt to convert it from BGR to grayscale? (Also, it's rather puzzling why you'd call the variable to hold the result of such operation "color")– Dan Mašek
Nov 14 '18 at 21:05
@DanMašek, I probably should have excluded that from the sample and should have restated for
threshold
. I am having the same issue when removingcvtColor
with the same error of "System.AccessViolationException: 'Attempted to read or write protected memory'". I believe it most likely has to do with how I am originally formatting my Mat container.– NewToLiving
Nov 14 '18 at 21:17
In that case it would seem to be related to your
e
object. Hard to say without a lot more details. I suggest you edit your question and add relevant details (such as the specific error you receive, since that's quite significant).– Dan Mašek
Nov 14 '18 at 21:23
1
if there are 3*width*height elements in pinPtrArray then choose Mat im(e->Width,e->Height, CV_8UC3, pinPtrArray); to signalize it is a color image in the beginning. If there is only one channel you can't convert BGR2GRAY
– Micka
Nov 14 '18 at 22:01