Skip to content

Commit

Permalink
capture camera frame change.
Browse files Browse the repository at this point in the history
  • Loading branch information
aang7 committed May 3, 2018
1 parent 9c589bd commit d844cf6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion imageutils.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//#include <opencv2/core/utility.hpp>

#include <opencv/cv.h>
#include "opencv2/imgproc.hpp"
#include "opencv2/videoio.hpp"
Expand Down
38 changes: 30 additions & 8 deletions pixui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ void ImGui::ShowPixui(bool *p_open)


static OpenCVImage testImage;
static OpenCVImage webcamImage;

if (ImGui::Selectable("Show tester image", &show_tester_image))
{
Expand Down Expand Up @@ -213,27 +214,26 @@ void ImGui::ShowPixui(bool *p_open)
ImVec2 pos = ImGui::GetCursorScreenPos(); //Pocision actual
if (open_camera)
{
cv::Mat frame;

if (!camera.isOpened())
{
if (camera.open(cam_id))
{
camera.set(CV_CAP_PROP_FRAME_WIDTH,320);
camera.set(CV_CAP_PROP_FRAME_HEIGHT,240);
camera.set(CV_CAP_PROP_FRAME_WIDTH,800);
camera.set(CV_CAP_PROP_FRAME_HEIGHT,640);
}
else
std::cout << "camera don't found" << std::endl;
}
else
{

cv::Mat frame;
camera.read(frame); // get the cam image and storage it in frame variable
if (*camera_image.getTexture() != 0)
camera_image.UpdateMat(frame, true);
else
camera_image.LoadCVMat(frame, true);


}
ImGui::GetWindowDrawList()->AddImage((void*)*camera_image.getTexture(), pos, ImVec2(pos.x + size.x, pos.y + size.y));

Expand All @@ -243,11 +243,33 @@ void ImGui::ShowPixui(bool *p_open)
camera.release();
open_camera = false;
}


static int webcamframe_counter = 0;
if (ImGui::Button("Capture frame"))
{
camera.set(CV_CAP_PROP_FRAME_WIDTH,1024);
camera.set(CV_CAP_PROP_FRAME_HEIGHT,768);
if(!frame.empty())
{

camera.read(frame);
webcamframe_counter++;
stringstream ss;
ss << "Webcam frame: " << webcamframe_counter;
data.push_back(OpenCVImage());
data.back().LoadCVMat(frame);
data.at(data.size() - 1).SetName(ss.str().c_str());
camera.set(CV_CAP_PROP_FRAME_WIDTH,800);
camera.set(CV_CAP_PROP_FRAME_HEIGHT, 640);

//webcamImage.LoadCVMat(frame, false);
}
}

//ImGui::Selectable("Show Webcam Frame", webcamImage.getOpen());
//showImage("Webcam frame", webcamImage.getOpen(), webcamImage.getTexture());

}

if (show_tester_image) {
showImage("Tester", &show_tester_image, testImage.getTexture());
}
Expand Down

0 comments on commit d844cf6

Please sign in to comment.