Skip to content

Commit

Permalink
generalize CineStat tool to VideoStat to get info on video files
Browse files Browse the repository at this point in the history
  • Loading branch information
dicengine committed Feb 3, 2022
1 parent 05df177 commit 5c74696
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
8 changes: 4 additions & 4 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ install(TARGETS DICe_CineToTiff
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
)

add_executable(DICe_CineStat DICe_CineStat.cpp)
target_link_libraries(DICe_CineStat ${DICE_LIBRARIES} ${DICE_TEST_LIBRARIES})
add_executable(DICe_VideoStat DICe_VideoStat.cpp)
target_link_libraries(DICe_VideoStat ${DICE_LIBRARIES} ${DICE_TEST_LIBRARIES})

install(TARGETS DICe_CineStat
install(TARGETS DICe_VideoStat
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
)

Expand Down Expand Up @@ -83,7 +83,7 @@ target_link_libraries(DICe_Cal ${DICE_LIBRARIES} ${DICE_TEST_LIBRARIES})
add_executable(DICe_Epiline DICe_Epiline.cpp)
target_link_libraries(DICe_Epiline ${DICE_LIBRARIES} ${DICE_TEST_LIBRARIES})

set_target_properties(DICe_CineToTiff DICe_CineStat DICe_Diff DICe_DiffAvg DICe_CrossInit DICe_Cal DICe_Epiline
set_target_properties(DICe_CineToTiff DICe_VideoStat DICe_Diff DICe_DiffAvg DICe_CrossInit DICe_Cal DICe_Epiline
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${DICE_OUTPUT_PREFIX}/lib"
ARCHIVE_OUTPUT_DIRECTORY "${DICE_OUTPUT_PREFIX}/lib"
Expand Down
37 changes: 24 additions & 13 deletions tools/DICe_CineStat.cpp → tools/DICe_VideoStat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
// ************************************************************************
// @HEADER

/*! \file DICe_CineToTiff.cpp
\brief Utility for exporting cine files to tiff files
/*! \file DICe_VideoStat.cpp
\brief Utility for exporting video files to tiff files
*/

#include <DICe.h>
Expand Down Expand Up @@ -69,8 +69,8 @@ int main(int argc, char *argv[]) {
if(argc>=2){
std::string help = argv[1];
if(help=="-h"||argc>2){
std::cout << " DICe_CineStat (writes a file with the cine index range) " << std::endl;
std::cout << " Syntax: DICe_CineStat <cine_file_name>" << std::endl;
std::cout << " DICe_VideoStat (writes a file with the valid video index range) " << std::endl;
std::cout << " Syntax: DICe_VideoStat <video_file_name>" << std::endl;
exit(0);
}
}
Expand All @@ -81,14 +81,25 @@ int main(int argc, char *argv[]) {
DEBUG_MSG(argv[i]);
}
std::string fileName = argv[1];
*outStream << "Cine file name: " << fileName << std::endl;
Teuchos::RCP<hypercine::HyperCine> hc = DICe::utils::Video_Singleton::instance().hypercine(fileName,hypercine::HyperCine::TO_8_BIT);
*outStream << "\nCine read successfully\n" << std::endl;

const int_t num_images = hc->file_frame_count();
const int_t first_frame = hc->file_first_frame_id();
const int_t last_frame = first_frame + num_images - 1;
const int_t frame_rate = hc->frame_rate();
*outStream << "Video file name: " << fileName << std::endl;

int_t num_images, first_frame, last_frame, frame_rate;

if(DICe::utils::is_cine_file(fileName)){
Teuchos::RCP<hypercine::HyperCine> hc = DICe::utils::Video_Singleton::instance().hypercine(fileName,hypercine::HyperCine::TO_8_BIT);
*outStream << "\nCine read successfully\n" << std::endl;
num_images = hc->file_frame_count();
first_frame = hc->file_first_frame_id();
last_frame = first_frame + num_images - 1;
frame_rate = hc->frame_rate();
}else{
Teuchos::RCP<cv::VideoCapture> vc = DICe::utils::Video_Singleton::instance().video_capture(fileName);
*outStream << "\nVideo read successfully\n" << std::endl;
num_images = vc->get(cv::CAP_PROP_FRAME_COUNT);
first_frame = 0;
last_frame = first_frame + num_images - 1;
frame_rate = vc->get(cv::CAP_PROP_FPS);
}

*outStream << "Num frames: " << num_images << std::endl;
*outStream << "First frame: " << first_frame << std::endl;
Expand All @@ -97,7 +108,7 @@ int main(int argc, char *argv[]) {

// write stats to file
create_directory(".dice");
std::FILE * filePtr = fopen(".dice/.cine_stats.dat","w");
std::FILE * filePtr = fopen(".dice/.video_stats.dat","w");
fprintf(filePtr,"%i %i %i %i\n",num_images,first_frame,last_frame,frame_rate);
fclose(filePtr);

Expand Down

0 comments on commit 5c74696

Please sign in to comment.