Skip to content

Commit

Permalink
Merge pull request #5 from BTK203/master
Browse files Browse the repository at this point in the history
Fixed the spontaneous crashing when using JeVois
  • Loading branch information
BTK203 authored Dec 1, 2019
2 parents 90b65ab + 5d11383 commit 28c9b20
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
21 changes: 17 additions & 4 deletions KiwiLight - Vision Code/KiwiLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ UIMode KiwiLightApp::mode = UIMode::UI_STREAM;
bool KiwiLightApp::lastImageGrabSuccessful = false;
bool KiwiLightApp::udpEnabled = false;
bool KiwiLightApp::streamThreadEnabled = true; //acts as a kind of "enable switch" for the streamthread because it seems to like starting when its not supposed to
bool KiwiLightApp::outImgInUse = false;
Mat KiwiLightApp::lastFrameGrabImage;
Window KiwiLightApp::win;
ConfigPanel KiwiLightApp::confInfo;
Expand Down Expand Up @@ -326,7 +327,13 @@ void KiwiLightApp::UpdateApp() {

//update the camera error label based on how successful thread is being
if(lastImageGrabSuccessful) {
//wait for the output image to be updated by other thread
while(KiwiLightApp::outImgInUse) {
usleep(10);
}
KiwiLightApp::outImgInUse = true;
KiwiLightApp::outputImage.Update(KiwiLightApp::lastFrameGrabImage);
KiwiLightApp::outImgInUse = false;
KiwiLightApp::cameraStatusLabel.SetText("");
} else {
KiwiLightApp::cameraStatusLabel.SetText("Camera Error!");
Expand Down Expand Up @@ -379,8 +386,9 @@ void KiwiLightApp::UpdateStreams() {
//attempt to loop the things
Mat displayImage;
switch(KiwiLightApp::mode) {
case UIMode::UI_STREAM:
displayImage = KiwiLightApp::TakeImage();
case UIMode::UI_STREAM: {
displayImage = KiwiLightApp::TakeImage();
}
break;
case UIMode::UI_RUNNER: {
std::string output = KiwiLightApp::runner.Iterate();
Expand All @@ -406,10 +414,15 @@ void KiwiLightApp::UpdateStreams() {
}
break;
}

// if successful, update the display image
if(KiwiLightApp::lastImageGrabSuccessful) {
if(KiwiLightApp::lastImageGrabSuccessful) {
//wait for out image to be used by other thread
while(KiwiLightApp::outImgInUse) {
usleep(10);
}
KiwiLightApp::outImgInUse = true;
KiwiLightApp::lastFrameGrabImage = displayImage;
KiwiLightApp::outImgInUse = false;
}
} catch(cv::Exception ex) {
std::cout << "An OpenCv Exception was encountered while running the Streaming thread!" << std::endl;
Expand Down
1 change: 1 addition & 0 deletions KiwiLight - Vision Code/KiwiLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ namespace KiwiLight {
static bool lastImageGrabSuccessful;
static bool udpEnabled;
static bool streamThreadEnabled;
static bool outImgInUse;
static Mat lastFrameGrabImage;
static int currentCameraIndex;

Expand Down

0 comments on commit 28c9b20

Please sign in to comment.