diff --git a/Image Aquisition Solution/all b/Image Aquisition Solution/all new file mode 100755 index 0000000000000000000000000000000000000000..fa41933be4c2f3723d6951f3ee443f231e0cb09a --- /dev/null +++ b/Image Aquisition Solution/all @@ -0,0 +1,5 @@ +#! /bin/sh + +./configure +./build +./run \ No newline at end of file diff --git a/Image Aquisition Solution/build b/Image Aquisition Solution/build new file mode 100755 index 0000000000000000000000000000000000000000..561f9030428b747716113e52c3126fb14bf7aeb9 --- /dev/null +++ b/Image Aquisition Solution/build @@ -0,0 +1,4 @@ +#! /bin/sh + +cd out/build; +make; diff --git a/Image Aquisition Solution/configure b/Image Aquisition Solution/configure new file mode 100755 index 0000000000000000000000000000000000000000..2000136242b5add7d547f08c2edfce9361a43f9b --- /dev/null +++ b/Image Aquisition Solution/configure @@ -0,0 +1,4 @@ +#! /bin/sh + + +cmake -S src -B out/build; \ No newline at end of file diff --git a/Image Aquisition Solution/run b/Image Aquisition Solution/run new file mode 100755 index 0000000000000000000000000000000000000000..1f24ef0dc86c8986eb4cc3b0f946b52e45481e1f --- /dev/null +++ b/Image Aquisition Solution/run @@ -0,0 +1,4 @@ +#! /bin/sh + +cd out/build; +./imageCapture \ No newline at end of file diff --git a/Image Aquisition Solution/src/CMakeLists.txt b/Image Aquisition Solution/src/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..b1926c3d63e9d87fb6f497e0e477f69ae9e8bad8 --- /dev/null +++ b/Image Aquisition Solution/src/CMakeLists.txt @@ -0,0 +1,30 @@ +cmake_minimum_required (VERSION 2.8) +project(imageCapture) + +set(raspicam_DIR "/usr/local/lib/cmake") +SET(public_hdrs_base raspicamtypes.h raspicam.h raspicam_still.h) + +find_package( + raspicam REQUIRED + wiringPi REQUIRED + Threads REQUIRED + ) + +add_executable ( + ${PROJECT_NAME} main.cpp + ) + +find_library( + WIRINGPI_LIBRARIES NAMES wiringPi + ) + +target_link_libraries( + ${PROJECT_NAME} + ${raspicam_LIBS} + ${WIRINGPI_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} + ) + +include_directories( + ${WIRINGPI_INCLUDE_DIRS} + ) \ No newline at end of file diff --git a/Image Aquisition Solution/src/archive/imageCaptureTest.cpp b/Image Aquisition Solution/src/archive/imageCaptureTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1db3006602b495a3f154375f868ec0870bc83c8f --- /dev/null +++ b/Image Aquisition Solution/src/archive/imageCaptureTest.cpp @@ -0,0 +1,109 @@ +#include <ctime> +#include <fstream> +#include <iostream> +#include <stdio.h> +#include <chrono> +#include <thread> +#include <wiringPi.h> +#include <raspicam/raspicam.h> + +const int WIDTH = 4056; +const int HEIGHT = 3040; + +using namespace std; +/* +int initialise(raspicam::RaspiCam_Still* Camera){ + + + + Camera->setCaptureSize(WIDTH,HEIGHT); + Camera->setWidth(WIDTH); + Camera->setHeight(HEIGHT); + + Camera->setEncoding( + raspicam::RASPICAM_ENCODING_RGB + ); + + Camera->setExposure( + raspicam::RASPICAM_EXPOSURE_OFF + ); + + Camera->setAWB( + raspicam::RASPICAM_AWB_OFF + ); + + Camera->setImageEffect( + raspicam::RASPICAM_IMAGE_EFFECT_NONE + ); + + Camera->setMetering( + raspicam::RASPICAM_METERING_AVERAGE + ); + + + Camera->commitParameters(); + + return 0; + +} +*/ + + +int main ( int argc,char **argv ) { + + raspicam::RaspiCam Camera; + //Init + Camera.setCaptureSize(WIDTH,HEIGHT); + Camera.setWidth(WIDTH); + Camera.setHeight(HEIGHT); + Camera.setFormat( + raspicam::RASPICAM_FORMAT_RGB + ); + + + //this_thread::sleep_for(std::chrono::milliseconds(1000)); + //Camera.commitParameters(); + + + cout<<"Opening Camera..."<<endl; + if ( !Camera.open()) {cerr<<"Error opening camera"<<endl;return -1;} + //EndInit + + + //Wait + cout << "Sleeping..."<<endl; + this_thread::sleep_for(std::chrono::milliseconds(3000)); + //EndWait + + //Capture + int length = Camera.getImageBufferSize(); + + cout << length << endl; + + unsigned char* data=new unsigned char[ length ]; + + cout << "HERE"<<endl; + Camera.grab(); + Camera.retrieve(data); + cout << "THERE"<<endl; + + //save + std::ofstream outFile ("test.rgb",std::ios::binary); + cout << Camera.getWidth() << " " <<Camera.getHeight()<< endl; + outFile<<"P6\n"<< Camera.getWidth() <<" "<< Camera.getHeight() <<" 255\n"; + + outFile.write ( ( char* ) data, length ); + + cout<<"Image saved "<<endl; + + //free resrources + delete data; + + //EndCapture + + Camera.release(); + cout << "Finished" << endl; + return 0; + +} + diff --git a/Image Aquisition Solution/src/archive/notmain.cpp b/Image Aquisition Solution/src/archive/notmain.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eaab5ff546a5c36bd69a38588efb0fc46a6e3b6a --- /dev/null +++ b/Image Aquisition Solution/src/archive/notmain.cpp @@ -0,0 +1,34 @@ +#include <ctime> +#include <fstream> +#include <iostream> +#include <wiringPi.h> +#include <raspicam/raspicam.h> +using namespace std; + +int main ( int argc,char **argv ) { + raspicam::RaspiCam Camera; //Cmaera object + //Open camera + cout<<"Opening Camera..."<<endl; + if ( !Camera.open()) {cerr<<"Error opening camera"<<endl;return -1;} + //wait a while until camera stabilizes + cout<<"Sleeping for 3 secs"<<endl; + + struct timespec req, rem; + req.tv_sec = 3000 / 1000; + nanosleep(&req, &rem); + + //capture + Camera.grab(); + //allocate memory + unsigned char *data=new unsigned char[ Camera.getImageTypeSize ( raspicam::RASPICAM_FORMAT_RGB )]; + //extract the image in rgb format + Camera.retrieve ( data,raspicam::RASPICAM_FORMAT_RGB );//get camera image + //save + std::ofstream outFile ( "raspicam_image.ppm",std::ios::binary ); + outFile<<"P6\n"<<Camera.getWidth() <<" "<<Camera.getHeight() <<" 255\n"; + outFile.write ( ( char* ) data, Camera.getImageTypeSize ( raspicam::RASPICAM_FORMAT_RGB ) ); + cout<<"Image saved at raspicam_image.ppm"<<endl; + //free resrources + delete data; + return 0; +} \ No newline at end of file diff --git a/Image Aquisition Solution/src/main.cpp b/Image Aquisition Solution/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5d86eeda507a05bee9836f815e04115695c32448 --- /dev/null +++ b/Image Aquisition Solution/src/main.cpp @@ -0,0 +1,148 @@ +#include <ctime> +#include <fstream> +#include <iostream> +#include <stdexcept> +#include <stdio.h> +#include <chrono> +#include <thread> +#include <wiringPi.h> +#include <raspicam/raspicam.h> + +using namespace std; + +const int PIN_TRIGGER_IN = 17; +const int PIN_TIMER_TRIGGER_OUT = 27; +const int PIN_STEPPER_TRIGGER_OUT = 14; +const int PIN_STEPPER_RESET_OUT = 15; + +const int WIDTH = 4056; +const int HEIGHT = 3040; +const int FRAMERATE = 1; + + +int cameraInit(raspicam::RaspiCam* camera){ + + camera->setCaptureSize(WIDTH, HEIGHT); + + camera->setWidth(WIDTH); + + camera->setHeight(HEIGHT); + + camera->setFormat(raspicam::RASPICAM_FORMAT_RGB); + + camera->setVideoStabilization(false); + + camera->setAWB(raspicam::RASPICAM_AWB_OFF); + + camera->setImageEffect(raspicam::RASPICAM_IMAGE_EFFECT_NONE); + + camera->setISO(100); + + //camera->setFrameRate(1); + camera->setShutterSpeed(1000000); + + camera->setSensorMode(3); + + cout<<"Opening Camera..."<<endl; + if ( !camera->open(false)) {cerr<<"Error opening camera"<<endl;return -1;} + + return 0; + +} + +int gpioInit(){ + + // Broadcom pin referencing + wiringPiSetupGpio(); + + // Set trigger pin as input + pinMode(PIN_TRIGGER_IN,INPUT); + pinMode(PIN_TIMER_TRIGGER_OUT,OUTPUT); + pinMode(PIN_STEPPER_TRIGGER_OUT,OUTPUT); + pinMode(PIN_STEPPER_RESET_OUT,OUTPUT); + + + digitalWrite(PIN_TIMER_TRIGGER_OUT,0); + digitalWrite(PIN_STEPPER_TRIGGER_OUT,0); + digitalWrite(PIN_STEPPER_RESET_OUT,0); + + + // Set pulldown + pullUpDnControl(PIN_TRIGGER_IN, PUD_DOWN); + pullUpDnControl(PIN_TIMER_TRIGGER_OUT, PUD_DOWN); + pullUpDnControl(PIN_STEPPER_TRIGGER_OUT, PUD_DOWN); + pullUpDnControl(PIN_STEPPER_RESET_OUT, PUD_DOWN); + + return 0; +} + +void save(string path, unsigned char* data, int length){ + + std::ofstream outFile (path, std::ios::binary); + + outFile<<"P6\n"<< WIDTH <<" "<< HEIGHT <<" 255\n"; + + outFile.write ( ( char* ) data, length ); + +} + +int capture( raspicam::RaspiCam* camera, string path ){ + + int length = camera->getImageBufferSize(); + unsigned char* data=new unsigned char[ length ]; + + camera->grab(); + camera->retrieve(data); + + save(path, data, length); + cout<<"Image saved "<<endl; + + //free resrources + delete data; + + return 0; +} + +int main(int argc, char** argv){ + raspicam::RaspiCam camera; + + // Setup gpio + gpioInit(); + + // Setup and configure camera + cameraInit(&camera); + /* + cout << "Waiting on trigger" << endl; + + + while( true ){ + if(digitalRead(PIN_TRIGGER_IN)){ + break; + } + } + */ + + + + /* + digitalWrite(PIN_STEPPER_TRIGGER_OUT,1); + this_thread::sleep_for(std::chrono::milliseconds(80)); + digitalWrite(PIN_STEPPER_TRIGGER_OUT,0); + this_thread::sleep_for(std::chrono::milliseconds(2000)); + "/home/pi/mnt/js-lpt/initialTesting/Test3/9.jpg" + */ + this_thread::sleep_for(std::chrono::milliseconds(1000)); + cout << "Starting capture" << endl; + + camera.startCapture(); + this_thread::sleep_for(std::chrono::milliseconds(125)); + digitalWrite(PIN_TIMER_TRIGGER_OUT,1); + this_thread::sleep_for(std::chrono::milliseconds(100)); + capture(&camera,argv[1]); + digitalWrite(PIN_TIMER_TRIGGER_OUT,0); + + + return 0; +} + + diff --git a/helper.h b/Timer Subsystem/helper.h similarity index 100% rename from helper.h rename to Timer Subsystem/helper.h diff --git a/helper.ino b/Timer Subsystem/helper.ino similarity index 100% rename from helper.ino rename to Timer Subsystem/helper.ino diff --git a/timer.ino b/Timer Subsystem/timer.ino similarity index 100% rename from timer.ino rename to Timer Subsystem/timer.ino