Ask Your Question
0

Selection depth area

asked Jun 27 '17

drvrh gravatar image

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 ?

Preview: (hide)

Comments

set a lot of break points,find where the code crash.

jsxyhelu gravatar imagejsxyhelu (Jun 28 '17)edit

2 answers

Sort by » oldest newest most voted
3

answered Jun 27 '17

berak gravatar image

updated Jun 27 '17

writing 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);
Preview: (hide)

Comments

update: StereoBM returns CV_16S disparity images, not CV_16U, so at<uint16_t> is also wrong.

berak gravatar imageberak (Jun 28 '17)edit

Thanks 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?

drvrh gravatar imagedrvrh (Jun 30 '17)edit
0

answered Jun 28 '17

J. Romeo gravatar image

What about using threshold on the depth image? Have you tried it?

Preview: (hide)

Comments

Yes, 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.

drvrh gravatar imagedrvrh (Jun 30 '17)edit

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.

drvrh gravatar imagedrvrh (Jul 3 '17)edit

Question Tools

1 follower

Stats

Asked: Jun 27 '17

Seen: 834 times

Last updated: Jun 28 '17