Ask Your Question
0

Selection depth area

asked 2017-06-27 05:52:15 -0500

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 ?

edit retag flag offensive close merge delete

Comments

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

jsxyhelu gravatar imagejsxyhelu ( 2017-06-28 02:10:12 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
3

answered 2017-06-27 06:00:22 -0500

berak gravatar image

updated 2017-06-27 06:13:18 -0500

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);
edit flag offensive delete link more

Comments

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

berak gravatar imageberak ( 2017-06-27 22:35:29 -0500 )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 ( 2017-06-30 00:34:39 -0500 )edit
0

answered 2017-06-28 06:06:20 -0500

J. Romeo gravatar image

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

edit flag offensive delete link more

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 ( 2017-06-30 00:31:33 -0500 )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 ( 2017-07-03 03:58:38 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-06-27 05:52:15 -0500

Seen: 73 times

Last updated: Jun 28 '17