# Bounding Box from specific View (SceneCapture)

**URL:** <https://forums.unrealengine.com/t/bounding-box-from-specific-view-scenecapture/434522>\
**Category:** Debugging, Optimization, & Profiling\
**Tags:** Debugging, scenecapture2d, projection, actor-blueprint, bounding-box, unreal-engine, question\
**Created:** [September 26, 2018, 9:22am UTC](https://forums.unrealengine.com/t/bounding-box-from-specific-view-scenecapture/434522 "2018-09-26T09:22:41Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![anonymous\_user\_c3e69a5a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c3e69a5a](https://forums.unrealengine.com/u/anonymous_user_c3e69a5a)\
**Post date:** [October 9, 2018, 8:51am UTC](https://forums.unrealengine.com/t/bounding-box-from-specific-view-scenecapture/434522/6 "2018-10-09T08:51:09Z")

</div>

For now I did find a workaround:  
I used Custom Depth Stencil to get a binary render texture (upper left in the picture) with only the Actor being white:

 ![256037-highresscreenshot00001.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/f/a/cfafd68fee79e6092320d7270f6fffe8fa0270a4.png)

Then I used a simple bounding box algorithm:

```
FBox2D UTryPixelAccess::calcBoundingFromBinary(UTextureRenderTarget2D * RenderTexture)
{
	TArray<FLinearColor> ImageData;
	FRenderTarget *RenderTarget = RenderTexture->GameThread_GetRenderTargetResource();
	RenderTarget->ReadLinearColorPixels(ImageData);

	FVector2D maxPoint(0, 0);
	FVector2D minPoint(RenderTexture->SizeX, RenderTexture->SizeY);

	for (int x = 0; x < RenderTexture->SizeX; x++) {
		for (int y = 0; y < RenderTexture->SizeY; y++) {
			int i = x + y * RenderTexture->SizeX;
			if (ImageData[i].R > 0.1) {
				// we a have white pixel
				if (x <= minPoint.X) {
					minPoint.X = x;
				}
				if(y <= minPoint.Y) {
					minPoint.Y = y;
				}
				if (x >= maxPoint.X) {
					maxPoint.X = x;
				}
				if (y >= maxPoint.Y) {
					maxPoint.Y = y;
				}
			}
		}
	}

	return FBox2D(minPoint, maxPoint);
}

```

Though, this is not very performant so if anyone has a better Idea, please reply!

---

_[View the full topic](https://forums.unrealengine.com/t/bounding-box-from-specific-view-scenecapture/434522)._
