Adding option for camera parameters with new interface.

This commit is contained in:
Tadas Baltrusaitis 2018-01-27 12:12:36 +00:00
parent bbe58b50a6
commit 0ffc272ff4
2 changed files with 38 additions and 12 deletions

View file

@ -133,7 +133,6 @@ namespace OpenFaceOffline
// Camera calibration parameters // Camera calibration parameters
public float fx = -1, fy = -1, cx = -1, cy = -1; public float fx = -1, fy = -1, cx = -1, cy = -1;
bool estimate_camera_parameters = true;
public MainWindow() public MainWindow()
{ {
@ -161,7 +160,7 @@ namespace OpenFaceOffline
{ {
for (int i = 0; i < filenames.Count; ++i) for (int i = 0; i < filenames.Count; ++i)
{ {
SequenceReader reader = new SequenceReader(filenames[i], false); SequenceReader reader = new SequenceReader(filenames[i], false, fx, fy, cx, cy);
ProcessSequence(reader); ProcessSequence(reader);
// Before continuing to next video make sure the user did not stop the processing // Before continuing to next video make sure the user did not stop the processing
@ -709,7 +708,7 @@ namespace OpenFaceOffline
string directory = openDirectory(); string directory = openDirectory();
if (!string.IsNullOrWhiteSpace(directory)) if (!string.IsNullOrWhiteSpace(directory))
{ {
SequenceReader reader = new SequenceReader(directory, true); SequenceReader reader = new SequenceReader(directory, true, fx, fy, cx, cy);
processing_thread = new Thread(() => ProcessSequence(reader)); processing_thread = new Thread(() => ProcessSequence(reader));
processing_thread.Name = "Image sequence processing"; processing_thread.Name = "Image sequence processing";
@ -789,7 +788,7 @@ namespace OpenFaceOffline
int width = cam_sec.selected_camera.Item2; int width = cam_sec.selected_camera.Item2;
int height = cam_sec.selected_camera.Item3; int height = cam_sec.selected_camera.Item3;
SequenceReader reader = new SequenceReader(cam_id, width, height); SequenceReader reader = new SequenceReader(cam_id, width, height, fx, fy, cx, cy);
processing_thread = new Thread(() => ProcessSequence(reader)); processing_thread = new Thread(() => ProcessSequence(reader));
processing_thread.Name = "Webcam processing"; processing_thread.Name = "Webcam processing";
@ -942,14 +941,6 @@ namespace OpenFaceOffline
fy = camera_params_entry_window.Fy; fy = camera_params_entry_window.Fy;
cx = camera_params_entry_window.Cx; cx = camera_params_entry_window.Cx;
cy = camera_params_entry_window.Cy; cy = camera_params_entry_window.Cy;
if(fx == -1 || fy == -1 || cx == -1 || cy == -1)
{
estimate_camera_parameters = true;
}
else
{
estimate_camera_parameters = false;
}
} }
} }

View file

@ -97,6 +97,29 @@ namespace UtilitiesOF {
} }
} }
SequenceReader(System::String^ filename, bool directory, float fx, float fy, float cx, float cy)
{
m_sequence_capture = new Utilities::SequenceCapture();
std::string name_std = msclr::interop::marshal_as<std::string>(filename);
bool success;
if (directory)
{
success = m_sequence_capture->OpenImageSequence(name_std, fx, fy, cx, cy);
}
else
{
success = m_sequence_capture->OpenVideoFile(name_std, fx, fy, cx, cy);
}
if (!success)
{
throw gcnew ReadingFailedException("Failed to open an image sequence");
}
}
// Can provide a webcam id // Can provide a webcam id
SequenceReader(int webcam_id, int width, int height) SequenceReader(int webcam_id, int width, int height)
{ {
@ -110,6 +133,18 @@ namespace UtilitiesOF {
} }
} }
SequenceReader(int webcam_id, int width, int height, float fx, float fy, float cx, float cy)
{
m_sequence_capture = new Utilities::SequenceCapture();
bool success = m_sequence_capture->OpenWebcam(webcam_id, width, height, fx, fy, cx, cy);
if (!success)
{
throw gcnew ReadingFailedException("Failed to open an image sequence");
}
}
OpenCVWrappers::RawImage^ GetNextImage() OpenCVWrappers::RawImage^ GetNextImage()
{ {
cv::Mat next_image = m_sequence_capture->GetNextFrame(); cv::Mat next_image = m_sequence_capture->GetNextFrame();