ladisk / pyidi

Python Image Displacement Identification
MIT License
27 stars 18 forks source link

Use other formats of video #20

Closed LX2035 closed 2 years ago

LX2035 commented 2 years ago

Hello, I'm very interested in your work, but I don't have a high-speed camera that can generate a .cih suffix, but I see you mentioned in the documentation that it can be converted, but I don't know how to achieve it , can you give me a sample reference, thank you very much!

klemengit commented 2 years ago

Hi LX2035!

We're happy to see people interested in the topic! Off course, I guess the conversion is not specifically mentioned anywhere. You can achieve the conversion using the pyMRAW package (on PyPI). Since pyMRAW was developed to open cih files, the conversion from np.ndarray to cih and mraw was also implemented in pyMRAW rather than in pyIDI.

Here is a simple example:

import pyMRAW
import numpy as np
import pyidi

# Generate a random image sequence of 1000 images of size 100x100 (this is what you get from your camera software)
vid = np.random.rand(1000, 100, 100)

# Generate a dictionary with video information, such as frame rate etc.
info_dict = {
  'Record Rate(fps)':1000
  }

# Call the `save_mraw` function
mraw_path, cih_path = pyMRAW.save_mraw(vid, save_path=r'./my_filename', info_dict=info_dict)

Now your image sequence is saved in my_filename.mraw file and the info is saved in the my_filename.cih file. You can now open the video using pyIDI:

video = pyidi.pyIDI('my_filename.cih')

The information you entered in the info_dict is now seen in video.info dictionary (the fields that were not given are left on default)

video.info

{'Record Rate(fps)': 1000, 'Shutter Speed(s)': 1.0, 'Total Frame': 1000, 'Original Total Frame': 1000, 'Start Frame': 0, 'Image Width': 100, 'Image Height': 100, 'Color Type': 'Mono', 'Color Bit': 16, 'File Format': 'MRaw', 'EffectiveBit Depth': 12, 'Comment Text': 'Generated sequence. Modify measurement info in created .cih file if necessary.', 'EffectiveBit Side': 'Lower'}

NOTE: If you want to know what information the info_dict accepts, check the keys of the video.info dictionary when you open one of the example files.

Hope this helps!

LX2035 commented 2 years ago

Hello, thank you very much, I also adopted my solution last night, concrete train of thought and see what you have said in the literature into numpy array way first, so I will first video frame by frame extraction, and then converted to gray image, so that each frame into a two-dimensional matrix, and then add the two-dimensional matrix according to the order to the implementation-defined three-dimensional matrices, This forms a large 3D matrix, which can be read directly using Pyidi's method, but your method is obviously more convenient, he let me directly use the original way, here again thank you!

I'm in the direction of civil engineering, is currently the undergraduate course in fourth grade, my graduation design topic is structure of the dynamic displacement,  but using structural vibration frequency vibration frequency without your paper so big, I also tried many methods, before you have recently begun to turn to optical flow method, until you see your this article, you make me feel shine at the moment, thank you very much!

Here's what I did before.

------------------ 原始邮件 ------------------ 发件人: "ladisk/pyidi" @.>; 发送时间: 2022年4月12日(星期二) 中午12:06 @.>; @.**@.>; 主题: Re: [ladisk/pyidi] Use other formats of video (Issue #20)

Hi LX2035!

We're happy to see people interested in the topic! Off course, I guess the conversion is not specifically mentioned anywhere. You can achieve the conversion using the pyMRAW package (on PyPI). Since pyMRAW was developed to open cih files, the conversion from np.ndarray to cih and mraw was also implemented in pyMRAW rather than in pyIDI.

Here is a simple example: import pyMRAW import numpy as np import pyidi # Generate a random image sequence of 1000 images of size 100x100 (this is what you get from your camera software) vid = np.random.rand(1000, 100, 100) # Generate a dictionary with video information, such as frame rate etc. info_dict = { 'Record Rate(fps)':1000 } # Call the save_mraw function mraw_path, cih_path = pyMRAW.save_mraw(vid, save_path=r'./my_filename', info_dict=info_dict)

Now your image sequence is saved in my_filename.mraw file and the info is saved in the my_filename.cih file. You can now open the video using pyIDI: video = pyidi.pyIDI('my_filename.cih')

The information you entered in the info_dict is now seen in video.info dictionary (the fields that were not given are left on default) video.info

{'Record Rate(fps)': 1000, 'Shutter Speed(s)': 1.0, 'Total Frame': 1000, 'Original Total Frame': 1000, 'Start Frame': 0, 'Image Width': 100, 'Image Height': 100, 'Color Type': 'Mono', 'Color Bit': 16, 'File Format': 'MRaw', 'EffectiveBit Depth': 12, 'Comment Text': 'Generated sequence. Modify measurement info in created .cih file if necessary.', 'EffectiveBit Side': 'Lower'}

NOTE: If you want to know what information the info_dict accepts, check the keys of the video.info dictionary when you open one of the example files.

Hope this helps!

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

jankoslavic commented 2 years ago

Hi @LX2035 we are happy you find the package and the papers helpful! Just in case you require it, please check here for papers that (most of them) use pyIDI: http://lab.fs.uni-lj.si/ladisk/?what=incfl&flnm=research_filtered.php&keyword=optical%20methods