如何使用特定结构从python中的IR相机加载DAT文件

发布于 2025-02-07 05:50:44 字数 498 浏览 0 评论 0原文

我尝试读取一个带有以下结构的DAT文件。这是来自IR相机的视频。我尝试了不同的方法,但是一路上总是会出现错误。我想以不同的文件格式将其转换为Python,因此我可以对其进行一些分析。

import csv
datContent = [i.strip().split() for i in open("./Test_s.dat",'rb').readlines()]
# write it as a new CSV file
with open("./Test_s.csv", "wb") as f:
    writer = csv.writer(f)
    writer.writerows(datContent)

I try to read a dat file with the structure given below. It is a video from an IR camera. I tried different methods, but I always get errors along the way. I would like to convert it in a different file format and load it in python, so I can do some analysis with it.

import csv
datContent = [i.strip().split() for i in open("./Test_s.dat",'rb').readlines()]
# write it as a new CSV file
with open("./Test_s.csv", "wb") as f:
    writer = csv.writer(f)
    writer.writerows(datContent)

Datastructure

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

¢蛋碎的人ぎ生 2025-02-14 05:50:44

读取不包括数据日志的标题字段的示例,因为没有提供定义:

我假设Little Endian,将模式中的第一个符号更改为'>'如果DAT文件使用Big Endian。

import struct

# whitespace between definitions is ignored
# 's' is special: 16s means a byte string of length 16, not 16 single bytes
# 6H will return 6 seperate uint16 values
header_pattern = '< 4s 6H d 16s 16s 16s 16s 6f H 16s H 2B 4H'

# verifiyng size of our pattern: 2060-1918 => 142
print(struct.calcsize(header_pattern))

# read file
with open('./Test_s.dat' 'rb') as f:
    header_bytes = f.read(142)

    # unpack bytes
    header_values = struct.struct.unpack(pattern, header_bytes)
    print(len(header_values))  # we expect 27 values

    # skip data log, can also use f.seek()
    f.read(1918)

    # handle each image header and data
    ...

我希望这足以让您前进,请记住,您需要从某些标头值计算图像数据大小。

我看不到图像计数的标题,因此您可能必须阅读直到文件结束。

Example to read the header fields excluding the data log, since no definition was provided:

I assumed little endian, change the first symbol in the pattern to '>' if the dat file used big endian.

import struct

# whitespace between definitions is ignored
# 's' is special: 16s means a byte string of length 16, not 16 single bytes
# 6H will return 6 seperate uint16 values
header_pattern = '< 4s 6H d 16s 16s 16s 16s 6f H 16s H 2B 4H'

# verifiyng size of our pattern: 2060-1918 => 142
print(struct.calcsize(header_pattern))

# read file
with open('./Test_s.dat' 'rb') as f:
    header_bytes = f.read(142)

    # unpack bytes
    header_values = struct.struct.unpack(pattern, header_bytes)
    print(len(header_values))  # we expect 27 values

    # skip data log, can also use f.seek()
    f.read(1918)

    # handle each image header and data
    ...

I hope this is enough to get you going, keep in mind you need calculate the image data size from some header values.

I cannot see a header for image count, so you probably have to read until the file ends.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文