Closed JiamingSuen closed 7 years ago
I think it should work fine. If you look in to this function, it takes byte arrays for color
, depth
and stencil
buffers and save them in one tiff
file. For debugging you can try modifying this function and save depth
and stencil
buffers in separate files.
Also note that you can't interpret/use these buffers as they are, you need to transform them as pointed in the section (III B) Technical Approach -Internal Engine Buffers of paper.
I managed to capture the depth buffer by turning MSAA off in the graphics settings, but the stencil page of tiff file is still all black. The captured depth looks like this, with bottom left corner all zero for unknown reason(it's width is not equal to the map). This is the captured color:
@muaz-git What do you mean by "transform"? Do you mean the depth buffer is stored as the logarithm of the actual depth? I'm not sure if the linearization has already been done by the native plugin. I would like to post the captured tiff file if needed. @muaz-git What's your process on this project, did you successfully captured all the data? It would be nice if you can share your configuration/dll/environment etc.. Thanks for all your help!
I tried tweak with other graphics settings but nothing helped with capturing stencil. I'll try to dig more.
@JiamingSuen Try turning off HUD for map. I guess no linearization has been done in native part. Follow this tutorial to linearize the depth, I haven't tried it yet but I guess it should work. I looked in to the code the other day and it seems like this part of code is saving projection matrix from where you can fetch z_near
and z_far
(which you need to linearize the depth map.)
In order to correctly interpret stencil map, you need to read only bottom 4 bits of each byte (pixel) to fetch each object ID (Note: These are only object IDs and you may need use pseudo coloring to visualize them). I am still working on the pipeline of completely automatic annotation. I will share all my stuff once I am done.
By turning off HUD and Radar, stencil is successfully captured. Thanks a lot @muaz-git !! I'll be continue working on depth linearization, looking forward to your result on semantic tag! I think we can work together to publish a complete guide for this project after the post processing, which is really needed for others.
@JiamingSuen Hi, how did you visualize the "color.raw" and "depth.raw" images in matlab? I got the raw files but failed to convert to normal format. Thanks.
@tyzaizl The native plugin is not supposed to be used directly according to the paper, use the managed plugin instead. After compile and some tweaking you should get a tiff file with 5 color pages, 1 depth page, 1 stencil page. Use the following python code to read the tiff image:
from PIL import Image, ImageFile, TiffImagePlugin
import matplotlib.pyplot as plt
import numpy as np
ImageFile.LOAD_TRUNCATED_IMAGES = True
TiffImagePlugin.READ_LIBTIFF = True
im = Image.open('./info36.tiff') # with your own image path.
im.seek(1) # use seek() to switch between pages
@JiamingSuen Thank you for replay, It seems I just got raw files by native plugin. When I came to managed plugin, something confused me:
when I copied ScriptHookVDotNet2.dll and ScriptHookVDotNet.asi into GTAV directory, GTAV will be crashed. I don't konw why. I tried ScriptHookVDotNet v2.10.3, v2.10.2 and v2.10.1, and all failed.
how to connect to sql dataset, in managed plugin README.md it said that,
"In order the connect to the database the managed plugins needs to know your database information. This is provided in an ini file that looks like the following:
[Database]
ConnectionString=
what kind of ini file should be created and where should this file located? directly in GTAV directory?
here are the log files: ScriptHookVDotNet2.log ScriptHookV.log GTANativePlugin.log
It seems that can't update NuGet packages. This time I succeed to start GTAV, but when I pressed "N" or "n" nothing happened. here are the log files: ScriptHookVDotNet2.log [15:34:49] [DEBUG] Created script domain 'ScriptDomain_679CB73C' with v2.10.2. [15:34:49] [DEBUG] Loading scripts from 'D:\tools\Grand Theft Auto V\scripts' into script domain 'ScriptDomain_679CB73C' ... [15:34:49] [INFO] Loading assembly 'AWSSDK.dll' ... [15:34:50] [DEBUG] Found 0 script(s) in 'AWSSDK.dll'. [15:34:50] [INFO] Loading assembly 'BitMiracle.LibTiff.NET.dll' ... [15:34:50] [DEBUG] Found 0 script(s) in 'BitMiracle.LibTiff.NET.dll'. [15:34:50] [INFO] Loading assembly 'FreeImageNET.dll' ... [15:34:50] [DEBUG] Found 0 script(s) in 'FreeImageNET.dll'. [15:34:50] [INFO] Loading assembly 'gdalconst_csharp.dll' ... [15:34:50] [DEBUG] Found 0 script(s) in 'gdalconst_csharp.dll'. [15:34:50] [INFO] Loading assembly 'gdal_csharp.dll' ... [15:34:50] [DEBUG] Found 0 script(s) in 'gdal_csharp.dll'. [15:34:50] [INFO] Loading assembly 'GTAVisionExport.dll' ... [15:34:50] [DEBUG] Found 0 script(s) in 'GTAVisionExport.dll'. [15:34:50] [INFO] Loading assembly 'GTAVisionUtils.dll' ... [15:34:50] [DEBUG] Found 0 script(s) in 'GTAVisionUtils.dll'. [15:34:50] [INFO] Loading assembly 'INIFileParser.dll' ... [15:34:50] [DEBUG] Found 0 script(s) in 'INIFileParser.dll'. [15:34:50] [INFO] Loading assembly 'MathNet.Numerics.dll' ... [15:34:50] [DEBUG] Found 0 script(s) in 'MathNet.Numerics.dll'. [15:34:50] [INFO] Loading assembly 'Microsoft.Extensions.DependencyInjection.Abstractions.dll' ... [15:34:50] [DEBUG] Found 0 script(s) in 'Microsoft.Extensions.DependencyInjection.Abstractions.dll'. [15:34:50] [INFO] Loading assembly 'Microsoft.Extensions.Logging.Abstractions.dll' ... [15:34:50] [DEBUG] Found 0 script(s) in 'Microsoft.Extensions.Logging.Abstractions.dll'. [15:34:50] [INFO] Loading assembly 'Microsoft.Extensions.Logging.dll' ... [15:34:50] [DEBUG] Found 0 script(s) in 'Microsoft.Extensions.Logging.dll'. [15:34:50] [INFO] Loading assembly 'NativeUI.dll' ... [15:34:50] [DEBUG] Found 1 script(s) in 'NativeUI.dll'. [15:34:50] [INFO] Loading assembly 'Npgsql.dll' ... [15:34:50] [DEBUG] Found 0 script(s) in 'Npgsql.dll'. [15:34:50] [INFO] Loading assembly 'ogr_csharp.dll' ... [15:34:50] [DEBUG] Found 0 script(s) in 'ogr_csharp.dll'. [15:34:50] [INFO] Loading assembly 'osr_csharp.dll' ... [15:34:50] [DEBUG] Found 0 script(s) in 'osr_csharp.dll'. [15:34:50] [WARNING] Skipped assembly 'ScriptHookVDotNet2.dll'. Please remove it from the directory. [15:34:50] [INFO] Loading assembly 'SharpDX.dll' ... [15:34:50] [DEBUG] Found 0 script(s) in 'SharpDX.dll'. [15:34:50] [INFO] Loading assembly 'SharpDX.Mathematics.dll' ... [15:34:50] [DEBUG] Found 0 script(s) in 'SharpDX.Mathematics.dll'. [15:34:50] [INFO] Loading assembly 'System.Runtime.InteropServices.RuntimeInformation.dll' ... [15:34:51] [DEBUG] Found 0 script(s) in 'System.Runtime.InteropServices.RuntimeInformation.dll'. [15:34:51] [INFO] Loading assembly 'System.Threading.Tasks.Extensions.dll' ... [15:34:51] [DEBUG] Found 0 script(s) in 'System.Threading.Tasks.Extensions.dll'. [15:34:51] [INFO] Loading assembly 'VAutodrive.dll' ... [15:34:51] [DEBUG] Found 0 script(s) in 'VAutodrive.dll'. [15:34:51] [INFO] Loading assembly 'VCommonFunctions.dll' ... [15:34:51] [DEBUG] Found 0 script(s) in 'VCommonFunctions.dll'. [15:34:51] [INFO] Loading assembly 'YamlDotNet.dll' ... [15:34:51] [DEBUG] Found 0 script(s) in 'YamlDotNet.dll'. [15:34:51] [DEBUG] Starting 1 script(s) ... [15:34:51] [DEBUG] Instantiating script 'NativeUI.BigMessageThread' in script domain 'ScriptDomain_679CB73C' ... [15:34:51] [DEBUG] Started script 'NativeUI.BigMessageThread'.
ScriptHookV.log // GTA V SCRIPT HOOK (build Sep 3 2017, v1.0.1180.2) // (C) Alexander Blade 2015-2017 [15:33:50] INIT: Started [15:33:50] INIT: Success, game version is VER_1_0_1180_2_NOSTEAM [15:33:50] INIT: Registering script 'ScriptHookVDotNet.asi' (0x00007FF85DEE1380) [15:33:58] INIT: Pool 1 extended [15:33:58] INIT: Pool 2 extended [15:33:58] INIT: Pool 3 extended [15:33:58] INIT: Pool 4 extended [15:34:04] INIT: GtaThread collection size 189 [15:34:04] INIT: wnd proc 0x00000000FFFF0195 [15:34:04] INIT: IDXGISwapChain 0x00007FF860110AA0 (0x00007FF8600B3610) [15:34:04] INIT: IDXGISwapChain set [15:34:04] INIT: DX init started [15:34:04] INIT: DX feature level B000 [15:34:04] INIT: DX init succeeded [15:34:47] CORE: Requesting thread creation [15:34:47] CORE: Creating threads [15:34:49] CORE: Started control thread, id 31 active 1 [15:34:49] CORE: Started thread 'ScriptHookVDotNet.asi' (0x00007FF85DEE1380), id 32 active 1 [15:34:49] CORE: Launching main() for 'ScriptHookVDotNet.asi' (0x00007FF85DEE1380), id 32
@tyzaizl you should have a look at the code in VisionExport.cs
and modify according to your needs.
Summary of my steps making the managed plugin work:
d3d11_4.h
is missing), another way to resolve this is to install the latest Windows 10 SDK within the Visual Studio installer(to get DirectX SDK).VisionExport.cs
to assign your own file saving location.ScriptHookVDotNet2.log
looks like the one I attached at the beginning, press PageUp to enable the plugin, use N key to start capture.@tyzaizl the ini file should be placed in the scripts directory.
@racinmat could you explain more details about the ini file? Thanks a lot
@TommyAnqi I have pull request with update README information. I described there the ini file, you can see it here. https://github.com/racinmat/GTAVisionExport/blob/master/managed/README.md Hope it helps.
@JiamingSuen Hiya, I'm getting garbled depth images out (example below). I have MSAA turned off, and for reflections too. Window resolution 1280x720, all of the graphics settings turned down to 'normal'. Any clues as to how I might resolve this? PS stencil looks like its garbled too.
@IanKirwan this is probably done using incorrect tiff reader. In this repo, tiff flags are heavily used, and some readers can'T deal with it. It's quite possible that it is correctly stored, but incorrectly visualized.
Hi @racinmat, The image above is in the following zip file. If you have the tools could you check it? 45871.zip I used the following code to view it. It treats the depth map as a 1280x720x1 array and scales the values to between 0-255:
from PIL import Image, ImageFile, TiffImagePlugin
import numpy as np
import cv2
ImageFile.LOAD_TRUNCATED_IMAGES = True
TiffImagePlugin.READ_LIBTIFF = True
im = Image.open('D:/Snapshots/Output/45871.tiff') # with your own image path.
im.seek(1) # use seek() to switch between pages
image = np.array(im.getdata()).reshape(im.size[1], im.size[0], 1)
maximg = np.max(image)
imageint = (image/maximg)*255
print(im.size[0])
print(im.size[1])
cv2.imshow('img',imageint)
cv2.waitKey(0)
Do you know if it matters whether the graphics settings are borderless window? full screen? What GTAV graphics settings are you using? I'm starting to get a feeling that the native code is not capturing the depth correctly, at least with my build of it.
If someone could zip up a working (for depth maps) 64bit GTAVisionNative.asi and GTAVisionNative.lib and post it here that would be a huge help. Many thanks in advance.
@IanKirwan Hi, sorry for the long pause, I didn't have time earlier. I am using windowed mode, not borderless. All my in-game graphics settings I am using are described in the readme, here: https://github.com/umautobots/GTAVisionExport/tree/master/managed#in-game-settings
I think it matters if you are using fullscrenn, borderless or wendowed, but I am not sure. When I am using windows mode, everything works for me fine.
I tried to visualize your data, and it really seems messed up. I tried source code which works for my tiff files exported from GTA. But I had no success, depth and stencil seems to be weird for me too.
But as I too had issues with tiff files, what worked for me was saving data into multiple tiff files instead of one file. So I have 1 tiff file to RGB, 1 file for depth, and 1 file for stencil. Then I was able to load data correctly with all classic python tiff libraries.
Saving into multiple tiffs can be seen here, in my fork: https://github.com/racinmat/GTAVisionExport/blob/multiple_tiffs/managed/GTAVisionUtils/ImageUtils.cs
Hi @racinmat No problem. We kind of got to the bottom of the issue, see issue 28. The problem seems to be that the depth buffer is actually much larger than the screen resolution for some machine setups. It gets garbled as the code tries to squash it into the tiff with smaller dimensions. I'm working on a mod to the native code to resample the buffer to fit when it is over sized. Many thanks for the details, though I had followed those instructions previously. My machine at work, works fine with borderless window at 1280x720 btw. I'm look forward to seeing your mods integrated into the master branch. Kind regards Ian
During my experiments I even noticed the buffer sizes change during a single session without any changes to the graphics settings (changes in weather can cause this apparently). So it may be necessary to implement some dynamic handling of this. Shouldn't it be possible to resize it as a 2d texture while it's still residing on the GPU? This would probably be the easiest and fastest option (although my expertise is limited in that regard). Is anyone familiar enough with the directx APIs in order to implement something like this?
On Sat, Feb 10, 2018, 12:50 IanKirwan notifications@github.com wrote:
Hi @racinmat https://github.com/racinmat No problem. We kind of got to the bottom of the issue, see issue 28 https://github.com/umautobots/GTAVisionExport/issues/28. The problem seems to be that the depth buffer is actually much larger than the screen resolution for some machine setups. It gets garbled as the code tries to squash it into the tiff with smaller dimensions. I'm working on a mod to the native code to resample the buffer to fit when it is over sized. Many thanks for the details, though I had followed those instructions previously. My machine at work, works fine with borderless window at 1280x720 btw. I'm look forward to seeing your mods integrated into the master branch. Kind regards Ian
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/umautobots/GTAVisionExport/issues/12#issuecomment-364646231, or mute the thread https://github.com/notifications/unsubscribe-auth/AM5gMLMTWmI9Kv-TwOyyQu2rbIkcS1Tjks5tTYKagaJpZM4P728w .
I'm trying code up a simple resample (down sample) that checks the screen size against the caputured depth buffer size and only does the resample if over sized. It doesnt work yet, as it crashes. It's a bit ugly, using mixed data types and your suggestion sounds like the smarter way to do it, though I have never done any Windows app programming before and my knowledge of c++ is from college 20 years ago. Still I might look into it.
Anyway, for now my buggy mod to export.cpp looks like this so far:
int screenResX;
int screenResY;
GRAPHICS::GET_SCREEN_RESOLUTION(&screenResX, &screenResY);
if (screenResX >= src_desc.Width)
{
for (int x = 0; x < src_desc.Width; ++x)
{
for (int y = 0; y < src_desc.Height; ++y)
{
const float* src_f = (const float*)((const char*)src_map.pData + src_map.RowPitch*y + (x * 8));
unsigned char* dst_p = &dst[src_desc.Width * 4 * y + (x * 4)];
unsigned char* stencil_p = &stencil[src_desc.Width * y + x];
memmove(dst_p, src_f, 4);
memmove(stencil_p, src_f + 1, 1);
}
}
}
else
{
// resize, for when depth map is bigger than screen image.
float scale = ((float) src_desc.Width) / ((float) screenResX);
dst = vector<unsigned char>(screenResY * screenResX * 4);
for (int x = 0; x < screenResX; ++x)
{
for (int y = 0; y < screenResY; ++y)
{
int scaledX = int(x*scale);
int scaledY = int(y*scale);
const float* src_f = (const float*)((const char*)src_map.pData + src_map.RowPitch*scaledY + (scaledX * 8));
unsigned char* dst_p = &dst[src_desc.Width * 4 * x + (y * 4)];
unsigned char* stencil_p = &stencil[src_desc.Width * scaledY + scaledX];
memmove(dst_p, src_f, 4);
memmove(stencil_p, src_f + 1, 1);
}
}
}
OK my (fixed) code mod appears to be working (and miraculously fixed stencil too) on this machine, both with standalone native and combined native/managed. It would be good if someone else could try this with their machine before I do a pull request. Here's the modified export.cpp unpack_depth() function:
static void unpack_depth(ID3D11Device* dev, ID3D11DeviceContext* ctx, ID3D11Resource* src, vector<unsigned char>& dst, vector<unsigned char>& stencil)
{
// static void GET_SCREEN_RESOLUTION(int* x, int* y) { invoke<Void>(0x888D57E407E63624, x, y); } // 0x888D57E407E63624 0x29F3572F
HRESULT hr = S_OK;
int screenResX;
int screenResY;
ComPtr<ID3D11Texture2D> src_tex;
GRAPHICS::GET_SCREEN_RESOLUTION(&screenResX, &screenResY);
hr = src->QueryInterface(__uuidof(ID3D11Texture2D), &src_tex);
if (hr != S_OK) throw std::system_error(hr, std::system_category());
D3D11_TEXTURE2D_DESC src_desc;
src_tex->GetDesc(&src_desc);
assert(src_desc.Format == DXGI_FORMAT_R32G8X24_TYPELESS);
D3D11_MAPPED_SUBRESOURCE src_map = { 0 };
hr = ctx->Map(src, 0, D3D11_MAP_READ, 0, &src_map);
if (hr != S_OK) throw std::system_error(hr, std::system_category());
if (dst.size() != src_desc.Height * src_desc.Width * 4) dst = vector<unsigned char>(src_desc.Height * src_desc.Width * 4);
if (stencil.size() != src_desc.Height * src_desc.Width) stencil = vector<unsigned char>(src_desc.Height * src_desc.Width);
if (screenResX >= src_desc.Width)
{
for (int x = 0; x < src_desc.Width; ++x)
{
for (int y = 0; y < src_desc.Height; ++y)
{
const float* src_f = (const float*)((const char*)src_map.pData + src_map.RowPitch*y + (x * 8));
unsigned char* dst_p = &dst[src_desc.Width * 4 * y + (x * 4)];
unsigned char* stencil_p = &stencil[src_desc.Width * y + x];
memmove(dst_p, src_f, 4);
memmove(stencil_p, src_f + 1, 1);
}
}
}
else
{
// resize, for when depth map is bigger than screen image.
float scale = ((float) src_desc.Width) / ((float) screenResX);
dst = vector<unsigned char>(screenResY * screenResX * 4);
for (int x = 0; x < screenResX; ++x) // screenResX
{
for (int y = 0; y < screenResY; ++y) //screenResY
{
int scaledX = int(x*scale);
int scaledY = int(y*scale);
const float* src_f = (const float*)((const char*)src_map.pData + int(src_map.RowPitch*scaledY + (scaledX * 8)));
unsigned char* dst_p = &dst[screenResX * 4 * y + (x * 4)];
unsigned char* stencil_p = &stencil[screenResX * y + x];
memmove(dst_p, src_f, 4);
memmove(stencil_p, src_f + 1, 1);
}
}
}
ctx->Unmap(src, 0);
}
See pull request 30
Hi there, I managed to compile the project and get it working(well partially) in the game. Frame capture is working fine but there's no depth and stencil in the result tiff image. The depth and stencil layer in tiff are just zeros and 255, while color frames are perfectly fine.
GTAVisionNative.asi
plugin is working normally with proper size raw file captured with 'L' key. I put the native asi file in GTA root folder and other compile output from 'managed' project in 'scripts' folder. I suspect the problem is caused by some linking problem with 'native' and 'managed', but the build process didn't generate any error. DoesGTAVisionUtils.dll
includeGTAVisionNative.asi
already? or these files should be put in some other order?Everything seems to be well in log files, this is content in
ScriptHookVDotNet2.log
:I would like to provide other log files if needed. Thanks!