fps test code added
This commit is contained in:
29
src/test code for fps/c++/basler/basler_read.cpp
Normal file
29
src/test code for fps/c++/basler/basler_read.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include<pylon/PylonIncludes.h>
|
||||
#include<pylon/InstantCamera.h>
|
||||
#include<time.h>
|
||||
using namespace std;
|
||||
using namespace Pylon;
|
||||
int main()
|
||||
{ CGrabResultPtr ptrGrabResult;
|
||||
int c=0;
|
||||
PylonInitialize();
|
||||
CInstantCamera camera( CTlFactory::GetInstance().CreateFirstDevice());
|
||||
camera.Open();
|
||||
camera.StartGrabbing();
|
||||
time_t start = time(NULL);
|
||||
while(camera.IsGrabbing())
|
||||
{
|
||||
if(time(NULL) - start < 60 )
|
||||
{
|
||||
camera.RetrieveResult( 5000, ptrGrabResult, TimeoutHandling_ThrowException);
|
||||
if (ptrGrabResult->GrabSucceeded())
|
||||
{
|
||||
c=c+1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ break;
|
||||
}
|
||||
}
|
||||
cout << c <<endl;
|
||||
}
|
||||
79
src/test code for fps/c++/basler/basler_write.cpp
Normal file
79
src/test code for fps/c++/basler/basler_write.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
#include <pylon/PylonIncludes.h>
|
||||
#include <time.h>
|
||||
|
||||
using namespace Pylon;
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
static const uint32_t c_countOfImagesToGrab = 1510;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
int exitCode = 0;
|
||||
|
||||
|
||||
PylonInitialize();
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
// Create an instant camera object with the camera device found first.
|
||||
CInstantCamera camera( CTlFactory::GetInstance().CreateFirstDevice());
|
||||
|
||||
// Print the model name of the camera.
|
||||
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
|
||||
|
||||
// The parameter MaxNumBuffer can be used to control the count of buffers
|
||||
// allocated for grabbing. The default value of this parameter is 10.
|
||||
camera.MaxNumBuffer = 5;
|
||||
|
||||
// Start the grabbing of c_countOfImagesToGrab images.
|
||||
// The camera device is parameterized with a default configuration which
|
||||
// sets up free-running continuous acquisition.
|
||||
camera.StartGrabbing( c_countOfImagesToGrab);
|
||||
|
||||
// This smart pointer will receive the grab result data.
|
||||
CGrabResultPtr ptrGrabResult;
|
||||
//camera.Width.SetValue(640);
|
||||
//camera.Height.SetValue(480);
|
||||
// Camera.StopGrabbing() is called automatically by the RetrieveResult() method
|
||||
// when c_countOfImagesToGrab images have been retrieved.
|
||||
time_t start = time(NULL);
|
||||
while ( camera.IsGrabbing())
|
||||
{
|
||||
CPylonImage target;
|
||||
CImageFormatConverter converter;
|
||||
// Wait for an image and then retrieve it. A timeout of 5000 ms is used.
|
||||
camera.RetrieveResult( 5000, ptrGrabResult, TimeoutHandling_ThrowException);
|
||||
|
||||
// Image grabbed successfully?
|
||||
if (ptrGrabResult->GrabSucceeded())
|
||||
{
|
||||
//converter.Convert(target, ptrGrabResult);
|
||||
String_t filename="images/image.tif";
|
||||
//cv::imwrite(name.str(), dst);
|
||||
//cv::Mat image(target.GetHeight(), target.GetWidth(), CV_8UC1,target.GetBuffer(),Mat::AUTO_STEP);
|
||||
CImagePersistence::Save( ImageFileFormat_Tiff, filename, ptrGrabResult);
|
||||
//cv::imwrite(filename, image);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Error: " << ptrGrabResult->GetErrorCode() << " " << ptrGrabResult->GetErrorDescription() << endl;
|
||||
}
|
||||
}
|
||||
time_t end = time(NULL);
|
||||
float a = (end-start);
|
||||
cout << a << endl;
|
||||
}
|
||||
catch (const GenericException &e)
|
||||
{
|
||||
// Error handling.
|
||||
cerr << "An exception occurred." << endl
|
||||
<< e.GetDescription() << endl;
|
||||
exitCode = 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
5
src/test code for fps/c++/basler/readme.txt
Normal file
5
src/test code for fps/c++/basler/readme.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
go to the folder where pylon library is installed in linux
|
||||
|
||||
/Downloads/pylon-5.1.0.12682-x86_64/Samples/C++/Grab
|
||||
|
||||
Make changes in makefile, if you want to run basler_read then change NAME:=basler_read.
|
||||
30
src/test code for fps/c++/imaging source/CMakeLists.txt
Normal file
30
src/test code for fps/c++/imaging source/CMakeLists.txt
Normal file
@@ -0,0 +1,30 @@
|
||||
project(tcamopencvsaveimage)
|
||||
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(OpenCV REQUIRED)
|
||||
|
||||
set( TISCAMERA_DIR /home/bvtest/projects/tiscamera-1.0)
|
||||
|
||||
message( ${TISCAMERA_DIR} )
|
||||
|
||||
if(NOT EXISTS( ${TISCAMERA_DIR}/examples/cpp/common/tcamcamera.h))
|
||||
message( "CONFIGURATION ERROR : TISCAMERA_DIR not set to tiscamera directory." )
|
||||
#return()
|
||||
endif()
|
||||
|
||||
pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0 gstreamer-app-1.0 gstreamer-video-1.0)
|
||||
pkg_check_modules(TCAMLIB tcam)
|
||||
|
||||
|
||||
include_directories( ${CMAKE_CURRENT_BINARY_DIR} /home/mahwish/tiscamera/examples/cpp/common ${GSTREAMER_INCLUDE_DIRS} ${TCAM_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} )
|
||||
add_definitions(${GSTREAMER_CFLAGS_OTHER})
|
||||
|
||||
add_executable(tcamopencvsaveimage main.cpp /home/mahwish/tiscamera/examples/cpp/common/tcamcamera.cpp )
|
||||
|
||||
target_link_libraries(tcamopencvsaveimage ${TCAMLIB_LIBRARIES} ${GSTREAMER_LIBRARIES} ${OpenCV_LIBS} )
|
||||
|
||||
install(TARGETS tcamopencvsaveimage RUNTIME DESTINATION bin)
|
||||
|
||||
21
src/test code for fps/c++/imaging source/README.md
Normal file
21
src/test code for fps/c++/imaging source/README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Tcam OpenCV Save Image
|
||||
This sample shows, how to to use save images from camera live stream using a callback and OpenCV,
|
||||
|
||||
## Prerequisits
|
||||
It uses the the examples/cpp/common/tcamcamera.cpp and .h files of the *tiscamera* repository as wrapper around the
|
||||
GStreamer code and property handling. Adapt the CMakeList.txt accordingly.
|
||||
|
||||
In "main.cpp" search the line which contents
|
||||
```TcamCamera cam("00001234");```
|
||||
and exchange "00001234" by the serial number of your camera.
|
||||
|
||||
|
||||
## Building
|
||||
In order to build the sample, open a terminal, enter the sample's directory. Then enter
|
||||
```
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
./tcamautofocus
|
||||
```
|
||||
153
src/test code for fps/c++/imaging source/main.cpp
Normal file
153
src/test code for fps/c++/imaging source/main.cpp
Normal file
@@ -0,0 +1,153 @@
|
||||
//////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
Tcam Software Trigger
|
||||
This sample shows, how to trigger the camera by software and use a callback for image handling.
|
||||
|
||||
Prerequisits
|
||||
It uses the the examples/cpp/common/tcamcamera.cpp and .h files of the *tiscamera* repository as wrapper around the
|
||||
GStreamer code and property handling. Adapt the CMakeList.txt accordingly.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "tcamcamera.h"
|
||||
#include <unistd.h>
|
||||
|
||||
#include "opencv2/opencv.hpp"
|
||||
#include<time.h>
|
||||
using namespace gsttcam;
|
||||
|
||||
// Create a custom data structure to be passed to the callback function.
|
||||
typedef struct
|
||||
{
|
||||
int ImageCounter;
|
||||
bool SaveNextImage;
|
||||
bool busy;
|
||||
cv::Mat frame;
|
||||
} CUSTOMDATA;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// List available properties helper function.
|
||||
void ListProperties(TcamCamera &cam)
|
||||
{
|
||||
// Get a list of all supported properties and print it out
|
||||
auto properties = cam.get_camera_property_list();
|
||||
std::cout << "Properties:" << std::endl;
|
||||
for(auto &prop : properties)
|
||||
{
|
||||
std::cout << prop->to_string() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Callback called for new images by the internal appsink
|
||||
GstFlowReturn new_frame_cb(GstAppSink *appsink, gpointer data)
|
||||
{
|
||||
int width, height ;
|
||||
const GstStructure *str;
|
||||
|
||||
// Cast gpointer to CUSTOMDATA*
|
||||
CUSTOMDATA *pCustomData = (CUSTOMDATA*)data;
|
||||
if( !pCustomData->SaveNextImage)
|
||||
return GST_FLOW_OK;
|
||||
pCustomData->SaveNextImage = false;
|
||||
|
||||
pCustomData->ImageCounter++;
|
||||
|
||||
// The following lines demonstrate, how to acces the image
|
||||
// data in the GstSample.
|
||||
GstSample *sample = gst_app_sink_pull_sample(appsink);
|
||||
|
||||
GstBuffer *buffer = gst_sample_get_buffer(sample);
|
||||
|
||||
GstMapInfo info;
|
||||
|
||||
gst_buffer_map(buffer, &info, GST_MAP_READ);
|
||||
|
||||
if (info.data != NULL)
|
||||
{
|
||||
// info.data contains the image data as blob of unsigned char
|
||||
|
||||
GstCaps *caps = gst_sample_get_caps(sample);
|
||||
// Get a string containg the pixel format, width and height of the image
|
||||
str = gst_caps_get_structure (caps, 0);
|
||||
|
||||
if( strcmp( gst_structure_get_string (str, "format"),"BGRx") == 0)
|
||||
{
|
||||
// Now query the width and height of the image
|
||||
gst_structure_get_int (str, "width", &width);
|
||||
gst_structure_get_int (str, "height", &height);
|
||||
|
||||
//Create a cv::Mat, copy image data into that and save the image.
|
||||
pCustomData->frame.create(height,width,CV_8UC(4));
|
||||
memcpy( pCustomData->frame.data, info.data, width*height*4);
|
||||
char ImageFileName[256];
|
||||
sprintf(ImageFileName,"images/image%05d.tif", pCustomData->ImageCounter);
|
||||
cv::imwrite(ImageFileName,pCustomData->frame);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Calling Unref is important!
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
gst_sample_unref(sample);
|
||||
std::cout << pCustomData->ImageCounter << std::endl;
|
||||
// Set our flag of new image to true, so our main thread knows about a new image.
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
gst_init(&argc, &argv);
|
||||
// Declare custom data structure for the callback
|
||||
CUSTOMDATA CustomData;
|
||||
|
||||
CustomData.ImageCounter = 0;
|
||||
CustomData.SaveNextImage = false;
|
||||
|
||||
|
||||
printf("Tcam OpenCV Image Sample\n");
|
||||
|
||||
// Open camera by serial number
|
||||
TcamCamera cam("46510087");
|
||||
|
||||
|
||||
// Set video format, resolution and frame rate
|
||||
cam.set_capture_format("BGRx", FrameSize{640,480}, FrameRate{120,1});
|
||||
|
||||
// Comment following line, if no live video display is wanted.
|
||||
//cam.enable_video_display(gst_element_factory_make("ximagesink", NULL));
|
||||
|
||||
// Register a callback to be called for each new frame
|
||||
cam.set_new_frame_callback(new_frame_cb, &CustomData);
|
||||
|
||||
// Start the camera
|
||||
cam.start();
|
||||
|
||||
// Uncomment following line, if properties shall be listed. Many of the
|
||||
// properties that are done in software are available after the stream
|
||||
// has started. Focus Auto is one of them.
|
||||
// ListProperties(cam);
|
||||
time_t start = time(NULL);
|
||||
while(time(NULL) - start < 60 )
|
||||
{
|
||||
CustomData.SaveNextImage = true; // Save the next image in the callcack call
|
||||
//sleep(2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Simple implementation of "getch()"
|
||||
//printf("Press Enter to end the program");
|
||||
//char dummyvalue[10];
|
||||
//scanf("%c",dummyvalue);
|
||||
|
||||
cam.stop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
24
src/test code for fps/python/(linux)basler_read.py
Normal file
24
src/test code for fps/python/(linux)basler_read.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from pypylon import pylon
|
||||
|
||||
import time
|
||||
|
||||
|
||||
camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())
|
||||
camera.Open()
|
||||
camera.StartGrabbing()
|
||||
c=0
|
||||
t_e=time.time() + 60
|
||||
while camera.IsGrabbing():
|
||||
if time.time() < t_e:
|
||||
grabResult = camera.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException)
|
||||
if grabResult.GrabSucceeded():
|
||||
c=c+1
|
||||
else:
|
||||
print("Error: ", grabResult.ErrorCode, grabResult.ErrorDescription)
|
||||
grabResult.Release()
|
||||
else:
|
||||
break
|
||||
|
||||
print c
|
||||
|
||||
|
||||
25
src/test code for fps/python/(linux)basler_write.py
Normal file
25
src/test code for fps/python/(linux)basler_write.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from pypylon import pylon
|
||||
import time,cv2
|
||||
|
||||
|
||||
countOfImagesToGrab = 1525
|
||||
|
||||
camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())
|
||||
#print("Using device ", camera.GetDeviceInfo().GetModelName())
|
||||
|
||||
camera.MaxNumBuffer = 10
|
||||
i=0
|
||||
camera.StartGrabbingMax(countOfImagesToGrab)
|
||||
t_s=time.time()
|
||||
while camera.IsGrabbing():
|
||||
grabResult = camera.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException)
|
||||
if grabResult.GrabSucceeded():
|
||||
img = grabResult.Array
|
||||
i=i+1
|
||||
cv2.imwrite("images/image%d.tif" %i,img)
|
||||
else:
|
||||
print("Error: ", grabResult.ErrorCode, grabResult.ErrorDescription)
|
||||
grabResult.Release()
|
||||
t_e=time.time()
|
||||
print t_e-t_s
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import time
|
||||
import numpy as np
|
||||
from pyicic.IC_ImagingControl import *
|
||||
#from pyicic.IC_Camera import C_FRAME_READY_CALLBACK
|
||||
|
||||
ic = IC_ImagingControl()
|
||||
ic.init_library()
|
||||
|
||||
cam_names = ic.get_unique_device_names()
|
||||
#print cam_names
|
||||
device_name = cam_names[0]
|
||||
|
||||
#print device_name
|
||||
|
||||
cam = ic.get_device(device_name)
|
||||
cam.open()
|
||||
#cam.reset_properties()
|
||||
|
||||
formats = cam.list_video_formats()
|
||||
#print formats
|
||||
cam.set_video_format(formats[2])
|
||||
cam.start_live()
|
||||
c=0
|
||||
#cam.register_frame_ready_callback(C_FRAME_READY_CALLBACK())
|
||||
t_e=time.time() + 60
|
||||
while time.time() < t_e:
|
||||
cam.snap_image()
|
||||
#cam.save_image('images/output%d.jpg' %c)
|
||||
c=c+1
|
||||
|
||||
print c
|
||||
cam.stop_live()
|
||||
cam.close()
|
||||
@@ -0,0 +1,33 @@
|
||||
import time
|
||||
import numpy as np
|
||||
from pyicic.IC_ImagingControl import *
|
||||
#from pyicic.IC_Camera import C_FRAME_READY_CALLBACK
|
||||
|
||||
ic = IC_ImagingControl()
|
||||
ic.init_library()
|
||||
|
||||
cam_names = ic.get_unique_device_names()
|
||||
#print cam_names
|
||||
device_name = cam_names[0]
|
||||
|
||||
#print device_name
|
||||
|
||||
cam = ic.get_device(device_name)
|
||||
cam.open()
|
||||
#cam.reset_properties()
|
||||
|
||||
formats = cam.list_video_formats()
|
||||
#print formats
|
||||
cam.set_video_format(formats[2])
|
||||
cam.start_live()
|
||||
c=0
|
||||
#cam.register_frame_ready_callback(C_FRAME_READY_CALLBACK())
|
||||
t_e=time.time() + 60
|
||||
while time.time() < t_e:
|
||||
cam.snap_image()
|
||||
#cam.save_image('images/output%d.jpg' %c)
|
||||
c=c+1
|
||||
|
||||
print c
|
||||
cam.stop_live()
|
||||
cam.close()
|
||||
30
src/test code for fps/python/opencv_read.py
Normal file
30
src/test code for fps/python/opencv_read.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import numpy as np
|
||||
import cv2,time
|
||||
|
||||
#ser = serial.Serial('COM8',57600)
|
||||
cap = cv2.VideoCapture(0)
|
||||
# Define the codec and create VideoWriter object
|
||||
t_end = time.time() + 60
|
||||
counter=0
|
||||
|
||||
while(cap.isOpened()):
|
||||
ret, frame = cap.read()
|
||||
if time.time() < t_end:
|
||||
|
||||
if (ret==True):
|
||||
counter=counter+1
|
||||
#cv2.imwrite("images/image%d.jpg" %counter,frame)
|
||||
|
||||
else:
|
||||
break
|
||||
|
||||
#end_time = time.time()
|
||||
#print t_e-t_s
|
||||
print counter
|
||||
#print str(end_time-start_time)
|
||||
# Release everything if job is finished
|
||||
cap.release()
|
||||
#out.release()
|
||||
cv2.destroyAllWindows()
|
||||
#rVideo()
|
||||
|
||||
30
src/test code for fps/python/opencv_write.py
Normal file
30
src/test code for fps/python/opencv_write.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import numpy as np
|
||||
import cv2,time
|
||||
|
||||
#ser = serial.Serial('COM8',57600)
|
||||
cap = cv2.VideoCapture(0)
|
||||
# Define the codec and create VideoWriter object
|
||||
t_end = time.time() + 60
|
||||
counter=0
|
||||
|
||||
while(cap.isOpened()):
|
||||
ret, frame = cap.read()
|
||||
if time.time() < t_end:
|
||||
|
||||
if (ret==True):
|
||||
counter=counter+1
|
||||
cv2.imwrite("images/image%d.jpg" %counter,frame)
|
||||
|
||||
else:
|
||||
break
|
||||
|
||||
#end_time = time.time()
|
||||
#print t_e-t_s
|
||||
print counter
|
||||
#print str(end_time-start_time)
|
||||
# Release everything if job is finished
|
||||
cap.release()
|
||||
#out.release()
|
||||
cv2.destroyAllWindows()
|
||||
#rVideo()
|
||||
|
||||
39
src/test code for fps/python/v4l2_capture_read.py
Normal file
39
src/test code for fps/python/v4l2_capture_read.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from PIL import Image
|
||||
import select
|
||||
import v4l2capture,time
|
||||
import subprocess
|
||||
import Queue,cv2
|
||||
|
||||
video = v4l2capture.Video_device("/dev/video0")
|
||||
#q=Queue.Queue()
|
||||
size_x, size_y = video.set_format(640, 480)
|
||||
|
||||
video.create_buffers(5)
|
||||
|
||||
#subprocess.check_call("v4l2-ctl -d /dev/video0 -c exposure_absolute=1/10",shell=True) # adjusting exposure time to 100 micro sec
|
||||
|
||||
video.queue_all_buffers()
|
||||
|
||||
video.start()
|
||||
|
||||
|
||||
c=0
|
||||
t_s=time.time() + 60
|
||||
while time.time() < t_s:
|
||||
select.select((video,), (), ())
|
||||
|
||||
image_data = video.read_and_queue()
|
||||
c=c+1
|
||||
#image = Image.frombytes("RGB", (size_x, size_y), image_data)
|
||||
#image.save("images/image%d.tiff" %c)
|
||||
|
||||
video.close()
|
||||
|
||||
print c
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
39
src/test code for fps/python/v4l2_capture_write.py
Normal file
39
src/test code for fps/python/v4l2_capture_write.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from PIL import Image
|
||||
import select
|
||||
import v4l2capture,time
|
||||
import subprocess
|
||||
import Queue,cv2
|
||||
|
||||
video = v4l2capture.Video_device("/dev/video0")
|
||||
#q=Queue.Queue()
|
||||
size_x, size_y = video.set_format(640, 480)
|
||||
|
||||
video.create_buffers(5)
|
||||
|
||||
#subprocess.check_call("v4l2-ctl -d /dev/video0 -c exposure_absolute=1/10",shell=True) # adjusting exposure time to 100 micro sec
|
||||
|
||||
video.queue_all_buffers()
|
||||
|
||||
video.start()
|
||||
|
||||
|
||||
c=0
|
||||
t_s=time.time() + 60
|
||||
while time.time() < t_s:
|
||||
select.select((video,), (), ())
|
||||
|
||||
image_data = video.read_and_queue()
|
||||
c=c+1
|
||||
image = Image.frombytes("RGB", (size_x, size_y), image_data)
|
||||
image.save("images/image%d.tiff" %c)
|
||||
|
||||
video.close()
|
||||
|
||||
print c
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
2
src/test code for fps/readme.txt
Normal file
2
src/test code for fps/readme.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
please refer the CRS_Backlog sheet for more information
|
||||
|
||||
Reference in New Issue
Block a user