OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Mon, 03 Jul 2017 03:58:38 -0500Selection depth areahttp://answers.opencv.org/question/162524/selection-depth-area/For later object detection it is necessary to remove the background and other information from a depth picture. The idea is based on examining individual pixels on the picture, getting the depth value and, based on the depth, painting the pixels in another color.
Two for loops run to the picture size through an individual pixel in an x and y direction. In this frame we can acquire information about the pixel depth, following is the condition execution. The condition is to keep the depth information in the range from 0.4 to 2 m.
The problem in my algorithm is, that the opencv core crashes, writes core dumped (Segmentation fault (core dumped)) and in addition reports that the variables are out of the given area.
Print:
....
X: 6 Y: 1
Depth: 2896
X: 7 Y: 1
Depth: 2884
X: 8 Y: 1
Depth: 2896
X: 1 Y: 1
Depth: 3351
X: 2 Y: 1
Depth: 3401
X: 1 Y: 1
Depth: 2921
X: 2 Y: 1
Depth: 2872
X: 3 Y: 1
Depth: 2860
X: 4 Y: 1
Depth: 2848
X: 5 Y: 1
Depth: 2860
X: 1 Y: 1
Depth: 3165
X: 2 Y: 1
Depth: 3093
X: 3 Y: 1
Depth: 2946
X: 4 Y: 1
Depth: 2946
X: 5 Y: 1
Depth: 2884
X: 6 Y: 1
Depth: 2860
X: 7 Y: 1
Depth: 2884
(stay in this forever loop)
Segmentation fault (core dumped)
My code is:
for(uint16_t y = 1; y <= _depth_intrin.height; y++){
for(uint16_t x = 1; x <= _depth_intrin.width; x++){
depth_value = depth16.at<uint16_t>(x, y);
if(depth_value == NULL){
return 0;
}
if(depth_value >= 2000){
depth16.at<cv::Vec3b>(cv::Point(x, y)) = 255;
}
if(depth_value <= 300){
depth16.at<cv::Vec3b>(cv::Point(x, y)) = 255;
}
cout << "X: " << x << " Y: " << y << endl;
cout << "Depth: " << depth_value << endl;
depth_value = 0;
}
}
Where I have a problem ?
Tue, 27 Jun 2017 05:52:15 -0500http://answers.opencv.org/question/162524/selection-depth-area/Comment by jsxyhelu for <p>For later object detection it is necessary to remove the background and other information from a depth picture. The idea is based on examining individual pixels on the picture, getting the depth value and, based on the depth, painting the pixels in another color.
Two for loops run to the picture size through an individual pixel in an x and y direction. In this frame we can acquire information about the pixel depth, following is the condition execution. The condition is to keep the depth information in the range from 0.4 to 2 m.</p>
<p>The problem in my algorithm is, that the opencv core crashes, writes core dumped (Segmentation fault (core dumped)) and in addition reports that the variables are out of the given area.</p>
<p>Print:
....
X: 6 Y: 1
Depth: 2896
X: 7 Y: 1
Depth: 2884
X: 8 Y: 1
Depth: 2896
X: 1 Y: 1
Depth: 3351
X: 2 Y: 1
Depth: 3401
X: 1 Y: 1
Depth: 2921
X: 2 Y: 1
Depth: 2872
X: 3 Y: 1
Depth: 2860
X: 4 Y: 1
Depth: 2848
X: 5 Y: 1
Depth: 2860
X: 1 Y: 1
Depth: 3165
X: 2 Y: 1
Depth: 3093
X: 3 Y: 1
Depth: 2946
X: 4 Y: 1
Depth: 2946
X: 5 Y: 1
Depth: 2884
X: 6 Y: 1
Depth: 2860
X: 7 Y: 1
Depth: 2884
(stay in this forever loop)
Segmentation fault (core dumped)</p>
<p>My code is:</p>
<pre><code> for(uint16_t y = 1; y <= _depth_intrin.height; y++){
for(uint16_t x = 1; x <= _depth_intrin.width; x++){
depth_value = depth16.at<uint16_t>(x, y);
if(depth_value == NULL){
return 0;
}
if(depth_value >= 2000){
depth16.at<cv::Vec3b>(cv::Point(x, y)) = 255;
}
if(depth_value <= 300){
depth16.at<cv::Vec3b>(cv::Point(x, y)) = 255;
}
cout << "X: " << x << " Y: " << y << endl;
cout << "Depth: " << depth_value << endl;
depth_value = 0;
}
}
</code></pre>
<p>Where I have a problem ? </p>
http://answers.opencv.org/question/162524/selection-depth-area/?comment=162628#post-id-162628set a lot of break points,find where the code crash.Wed, 28 Jun 2017 02:10:12 -0500http://answers.opencv.org/question/162524/selection-depth-area/?comment=162628#post-id-162628Answer by berak for <p>For later object detection it is necessary to remove the background and other information from a depth picture. The idea is based on examining individual pixels on the picture, getting the depth value and, based on the depth, painting the pixels in another color.
Two for loops run to the picture size through an individual pixel in an x and y direction. In this frame we can acquire information about the pixel depth, following is the condition execution. The condition is to keep the depth information in the range from 0.4 to 2 m.</p>
<p>The problem in my algorithm is, that the opencv core crashes, writes core dumped (Segmentation fault (core dumped)) and in addition reports that the variables are out of the given area.</p>
<p>Print:
....
X: 6 Y: 1
Depth: 2896
X: 7 Y: 1
Depth: 2884
X: 8 Y: 1
Depth: 2896
X: 1 Y: 1
Depth: 3351
X: 2 Y: 1
Depth: 3401
X: 1 Y: 1
Depth: 2921
X: 2 Y: 1
Depth: 2872
X: 3 Y: 1
Depth: 2860
X: 4 Y: 1
Depth: 2848
X: 5 Y: 1
Depth: 2860
X: 1 Y: 1
Depth: 3165
X: 2 Y: 1
Depth: 3093
X: 3 Y: 1
Depth: 2946
X: 4 Y: 1
Depth: 2946
X: 5 Y: 1
Depth: 2884
X: 6 Y: 1
Depth: 2860
X: 7 Y: 1
Depth: 2884
(stay in this forever loop)
Segmentation fault (core dumped)</p>
<p>My code is:</p>
<pre><code> for(uint16_t y = 1; y <= _depth_intrin.height; y++){
for(uint16_t x = 1; x <= _depth_intrin.width; x++){
depth_value = depth16.at<uint16_t>(x, y);
if(depth_value == NULL){
return 0;
}
if(depth_value >= 2000){
depth16.at<cv::Vec3b>(cv::Point(x, y)) = 255;
}
if(depth_value <= 300){
depth16.at<cv::Vec3b>(cv::Point(x, y)) = 255;
}
cout << "X: " << x << " Y: " << y << endl;
cout << "Depth: " << depth_value << endl;
depth_value = 0;
}
}
</code></pre>
<p>Where I have a problem ? </p>
http://answers.opencv.org/question/162524/selection-depth-area/?answer=162525#post-id-162525writing for loops here is a terrible idea, and should be avoided at any cost.
there are a couple of pitfalls there, and it seems, you hit ALL of them:
* `depth16.at<uint16_t>(y,x);` // welcome to row major world !
* if your image is CV_16U, you **must not** try to access it as ` depth16.at<cv::Vec3b>` (verboten)
* this is C++, not matlab, you have to start iterating at 0 and end at n-1.
* your depth image is 16_U, so in the [0..0xffff] range. a value of 255 does not make any sense, as well as 0.2 or 0.4 (expectation mismatch)
please delete all of it, and rather use builtin functions, like setTo():
depthimg.setTo(some_number, depthimg>3000);Tue, 27 Jun 2017 06:00:22 -0500http://answers.opencv.org/question/162524/selection-depth-area/?answer=162525#post-id-162525Comment by drvrh for <p>writing for loops here is a terrible idea, and should be avoided at any cost. </p>
<p>there are a couple of pitfalls there, and it seems, you hit ALL of them:</p>
<ul>
<li><code>depth16.at<uint16_t>(y,x);</code> // welcome to row major world !</li>
<li>if your image is CV_16U, you <strong>must not</strong> try to access it as <code>depth16.at<cv::Vec3b></code> (verboten)</li>
<li>this is C++, not matlab, you have to start iterating at 0 and end at n-1.</li>
<li>your depth image is 16_U, so in the [0..0xffff] range. a value of 255 does not make any sense, as well as 0.2 or 0.4 (expectation mismatch)</li>
</ul>
<p>please delete all of it, and rather use builtin functions, like setTo():</p>
<pre><code>depthimg.setTo(some_number, depthimg>3000);
</code></pre>
http://answers.opencv.org/question/162524/selection-depth-area/?comment=162887#post-id-162887Thanks for reply, but I have one problem. In my show image are displaying white spots, because camera detect reflection of light. How eliminate this spots?Fri, 30 Jun 2017 00:34:39 -0500http://answers.opencv.org/question/162524/selection-depth-area/?comment=162887#post-id-162887Comment by berak for <p>writing for loops here is a terrible idea, and should be avoided at any cost. </p>
<p>there are a couple of pitfalls there, and it seems, you hit ALL of them:</p>
<ul>
<li><code>depth16.at<uint16_t>(y,x);</code> // welcome to row major world !</li>
<li>if your image is CV_16U, you <strong>must not</strong> try to access it as <code>depth16.at<cv::Vec3b></code> (verboten)</li>
<li>this is C++, not matlab, you have to start iterating at 0 and end at n-1.</li>
<li>your depth image is 16_U, so in the [0..0xffff] range. a value of 255 does not make any sense, as well as 0.2 or 0.4 (expectation mismatch)</li>
</ul>
<p>please delete all of it, and rather use builtin functions, like setTo():</p>
<pre><code>depthimg.setTo(some_number, depthimg>3000);
</code></pre>
http://answers.opencv.org/question/162524/selection-depth-area/?comment=162610#post-id-162610update: StereoBM returns CV_16S disparity images, not CV_16U, so `at<uint16_t>` is also wrong.Tue, 27 Jun 2017 22:35:29 -0500http://answers.opencv.org/question/162524/selection-depth-area/?comment=162610#post-id-162610Answer by J. Romeo for <p>For later object detection it is necessary to remove the background and other information from a depth picture. The idea is based on examining individual pixels on the picture, getting the depth value and, based on the depth, painting the pixels in another color.
Two for loops run to the picture size through an individual pixel in an x and y direction. In this frame we can acquire information about the pixel depth, following is the condition execution. The condition is to keep the depth information in the range from 0.4 to 2 m.</p>
<p>The problem in my algorithm is, that the opencv core crashes, writes core dumped (Segmentation fault (core dumped)) and in addition reports that the variables are out of the given area.</p>
<p>Print:
....
X: 6 Y: 1
Depth: 2896
X: 7 Y: 1
Depth: 2884
X: 8 Y: 1
Depth: 2896
X: 1 Y: 1
Depth: 3351
X: 2 Y: 1
Depth: 3401
X: 1 Y: 1
Depth: 2921
X: 2 Y: 1
Depth: 2872
X: 3 Y: 1
Depth: 2860
X: 4 Y: 1
Depth: 2848
X: 5 Y: 1
Depth: 2860
X: 1 Y: 1
Depth: 3165
X: 2 Y: 1
Depth: 3093
X: 3 Y: 1
Depth: 2946
X: 4 Y: 1
Depth: 2946
X: 5 Y: 1
Depth: 2884
X: 6 Y: 1
Depth: 2860
X: 7 Y: 1
Depth: 2884
(stay in this forever loop)
Segmentation fault (core dumped)</p>
<p>My code is:</p>
<pre><code> for(uint16_t y = 1; y <= _depth_intrin.height; y++){
for(uint16_t x = 1; x <= _depth_intrin.width; x++){
depth_value = depth16.at<uint16_t>(x, y);
if(depth_value == NULL){
return 0;
}
if(depth_value >= 2000){
depth16.at<cv::Vec3b>(cv::Point(x, y)) = 255;
}
if(depth_value <= 300){
depth16.at<cv::Vec3b>(cv::Point(x, y)) = 255;
}
cout << "X: " << x << " Y: " << y << endl;
cout << "Depth: " << depth_value << endl;
depth_value = 0;
}
}
</code></pre>
<p>Where I have a problem ? </p>
http://answers.opencv.org/question/162524/selection-depth-area/?answer=162661#post-id-162661What about using threshold on the depth image? Have you tried it? Wed, 28 Jun 2017 06:06:20 -0500http://answers.opencv.org/question/162524/selection-depth-area/?answer=162661#post-id-162661Comment by drvrh for <p>What about using threshold on the depth image? Have you tried it? </p>
http://answers.opencv.org/question/162524/selection-depth-area/?comment=162885#post-id-162885Yes, I'am trying but has no good results. I am using this settings for treshold threshold(depth8u, dst2, 110, 255, cv::THRESH_OTSU);
after threshold I would like run inpaint between original depth image and return value from threshold function. Resulst is equal. Inpaint diameter value has 5.Fri, 30 Jun 2017 00:31:33 -0500http://answers.opencv.org/question/162524/selection-depth-area/?comment=162885#post-id-162885Comment by drvrh for <p>What about using threshold on the depth image? Have you tried it? </p>
http://answers.opencv.org/question/162524/selection-depth-area/?comment=163447#post-id-163447I am using this settings for treshold threshold(depth8u, dst2, 110, 255, cv::THRESH_OTSU); after threshold I would like run inpaint between original depth image and return value from threshold function. Resulst is equal. Inpaint diameter value has 5.Mon, 03 Jul 2017 03:58:38 -0500http://answers.opencv.org/question/162524/selection-depth-area/?comment=163447#post-id-163447