Skip to content

Commit

Permalink
Update for camera disconnection at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamvu committed Feb 22, 2022
1 parent c1b0974 commit 67c1f03
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 48 deletions.
43 changes: 37 additions & 6 deletions code_samples/013_object_tracking_GPIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ g++ 013_object_tracking_GPIO.cpp /usr/src/tensorrt/bin/common/logger.o ../lib/li
>>>>>> Execute the binary file by typing the following command...
./013_object_tracking_GPIO.out
Expand All @@ -33,6 +32,13 @@ g++ 013_object_tracking_GPIO.cpp /usr/src/tensorrt/bin/common/logger.o ../lib/li
#include <JetsonGPIO.h>
#include "unistd.h"

// Linux headers
# include <fcntl.h> // Contains file controls like O_RDWR
# include <errno.h> // Error integer and strerror() function
# include <termios.h> // Contains POSIX terminal control definitions
# include <unistd.h> // write(), read(), close()



static bool g_bExit = false;

Expand Down Expand Up @@ -72,8 +78,7 @@ namespace PAL

int main(int argc, char *argv[])
{



signal(SIGINT, signalHandler);

PAL::Internal::EnableDepth(false);
Expand Down Expand Up @@ -162,19 +167,43 @@ int main(int argc, char *argv[])
bool useDepth = false;

bool bDetectionPinActive = false;
int key = ' ';


int factor = 0;
PAL::Acknowledgement cam_ack;
//27 = esc key. Run the loop until the ESC key is pressed
while (!g_bExit)
{



PAL::Image left, right, depth, disparity;
Mat img, d;
if (useDepth)
PAL::GrabFrames(&left, &right, &depth);
cam_ack = PAL::GrabFrames(&left, &right, &depth);
else
PAL::GrabFrames(&left, &right);
cam_ack = PAL::GrabFrames(&left, &right);

if(cam_ack == PAL::Acknowledgement::FAILURE)
{
GPIO::output(camera_pin, 1);
GPIO::output(camera_pin_1, 1);
GPIO::output(camera_pin_2, 1);
GPIO::output(camera_pin_3, 1);
GPIO::output(detection_pin, 1);
PAL::CameraStatus();
GPIO::output(camera_pin, 0);
GPIO::output(camera_pin_1, 0);
GPIO::output(camera_pin_2, 0);
GPIO::output(camera_pin_3, 0);
continue;
}

//Convert PAL::Image to Mat
img = Mat(left.rows, left.cols, CV_8UC3, left.Raw.u8_data);



if (useDepth)
{
d = Mat(depth.rows, depth.cols, CV_32FC1, depth.Raw.f32_data);
Expand All @@ -184,6 +213,7 @@ int main(int argc, char *argv[])
d = cv::Mat::zeros(cv::Size(1, 1), CV_32FC1);
}


num = PAL::RunTrack(img, d, boxes, ids, depthValues, colours);


Expand All @@ -209,6 +239,7 @@ int main(int argc, char *argv[])

}



boxes.clear();
ids.clear();
Expand Down
87 changes: 45 additions & 42 deletions code_samples/014_UART_sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ int int_length(__uint16_t a)

int main(int argc, char *argv[])
{



signal(SIGINT, signalHandler);

cv::VideoCapture cap;
Expand Down Expand Up @@ -171,13 +172,6 @@ int main(int argc, char *argv[])
return 1;
}








int width, height;
if (PAL::Init(width, height, -1) != PAL::SUCCESS) //Connect to the PAL camera
{
Expand Down Expand Up @@ -219,17 +213,24 @@ int main(int argc, char *argv[])
const char* End = "E"; // Mark end of the frame
const char* new_frame = "D"; // Start of new index
const char* Check = "C"; // Mark Checksum

PAL::Acknowledgement cam_ack;

//27 = esc key. Run the loop until the ESC key is pressed
while(!g_bExit)
{
PAL::Image left, right, depth, disparity;
Mat img, d;
if (useDepth)
PAL::GrabFrames(&left, &right, &depth);
cam_ack = PAL::GrabFrames(&left, &right, &depth);
else
PAL::GrabFrames(&left, &right);
cam_ack = PAL::GrabFrames(&left, &right);

if(cam_ack == PAL::Acknowledgement::FAILURE)
{
PAL::CameraStatus();
continue;
}


//Convert PAL::Image to Mat
img = Mat(left.rows, left.cols, CV_8UC3, left.Raw.u8_data);
Expand All @@ -246,42 +247,44 @@ int main(int argc, char *argv[])

if(num)
{
// Writing Start of the frame to the serial port
write(serial_port, Start, 1);

printf("[INFO] START OF NEW FRAME\n");
char num_buffer[int_length(num)];
my_itoa(num, num_buffer);
write(serial_port, num_buffer, sizeof(num_buffer));
printf("Num of person detected: %d\n" , num);
if(useDepth)
{
for(int i=0; i<num; i++)
{
bool invalid = std::isnan(depthValues[i]) || (depthValues[i]<0) || (depthValues[i]>1000);
depthValues[i] = (invalid) ? 100: depthValues[i];
}

for(int i=0; i<num; i++)
{
char buffer[int_length(depthValues[i])];
my_itoa(depthValues[i], buffer);
printf(" DISTANCE : %d cm\n", (int)depthValues[i]);

write(serial_port, new_frame, 1);
write(serial_port, buffer, sizeof(buffer));
}
}
// Writing End of the frame to the serial port
write(serial_port, End, 1);
printf("[INFO] END OF THE FRAME\n\n");
// Writing Start of the frame to the serial port
write(serial_port, Start, 1);

printf("[INFO] START OF NEW FRAME\n");
char num_buffer[int_length(num)];
my_itoa(num, num_buffer);
write(serial_port, num_buffer, sizeof(num_buffer));
printf("Num of person detected: %d\n" , num);
if(useDepth)
{
for(int i=0; i<num; i++)
{
bool invalid = std::isnan(depthValues[i]) || (depthValues[i]<0) || (depthValues[i]>1000);
depthValues[i] = (invalid) ? 100: depthValues[i];
}

for(int i=0; i<num; i++)
{
char buffer[int_length(depthValues[i])];
my_itoa(depthValues[i], buffer);
printf(" DISTANCE : %d cm\n", (int)depthValues[i]);

write(serial_port, new_frame, 1);
write(serial_port, buffer, sizeof(buffer));
}
}
// Writing End of the frame to the serial port
write(serial_port, End, 1);
printf("[INFO] END OF THE FRAME\n\n");
}



boxes.clear();
ids.clear();
if(useDepth)
depthValues.clear();
depthValues.clear();
colours.clear();

}
Expand Down
Binary file modified lib/libPAL.so
100644 → 100755
Binary file not shown.

0 comments on commit 67c1f03

Please sign in to comment.