Compare commits
2 Commits
fa5a44bcbf
...
2a4d3516ca
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2a4d3516ca | ||
![]() |
947e52854d |
@ -2,7 +2,7 @@ PROJECT_NAME = AsynchronousGrabQt
|
|||||||
|
|
||||||
PROJECT_DIR = ../..
|
PROJECT_DIR = ../..
|
||||||
EXAMPLES_DIR = $(PROJECT_DIR)/../..
|
EXAMPLES_DIR = $(PROJECT_DIR)/../..
|
||||||
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
|
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
|
||||||
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
|
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
|
||||||
|
|
||||||
include $(MAKE_INCLUDE_DIR)/Common.mk
|
include $(MAKE_INCLUDE_DIR)/Common.mk
|
||||||
@ -13,47 +13,55 @@ BIN_DIR = binary/$(CONFIG_DIR)
|
|||||||
OBJ_DIR = object/$(CONFIG_DIR)
|
OBJ_DIR = object/$(CONFIG_DIR)
|
||||||
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
|
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
|
||||||
|
|
||||||
|
# Qt 工具路径
|
||||||
|
MOC = /usr/lib/aarch64-linux-gnu/qt5/bin/moc
|
||||||
|
UIC = /usr/lib/aarch64-linux-gnu/qt5/bin/uic
|
||||||
|
RCC = /usr/lib/aarch64-linux-gnu/qt5/bin/rcc
|
||||||
|
|
||||||
|
# 使用 pkg-config 获取 Qt 编译标志
|
||||||
|
QT_CFLAGS := $(shell pkg-config --cflags Qt5Core Qt5Gui Qt5Widgets)
|
||||||
|
QT_LIBS := $(shell pkg-config --libs Qt5Core Qt5Gui Qt5Widgets)
|
||||||
|
|
||||||
all: $(BIN_PATH)
|
all: $(BIN_PATH)
|
||||||
|
|
||||||
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
|
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
|
||||||
include $(MAKE_INCLUDE_DIR)/VimbaImageTransform.mk
|
include $(MAKE_INCLUDE_DIR)/VimbaImageTransform.mk
|
||||||
include $(MAKE_INCLUDE_DIR)/Qt.mk
|
|
||||||
|
|
||||||
SOURCE_DIR = $(PROJECT_DIR)/Source
|
SOURCE_DIR = $(PROJECT_DIR)/Source
|
||||||
|
|
||||||
INCLUDE_DIRS = -I$(SOURCE_DIR) \
|
INCLUDE_DIRS = -I$(SOURCE_DIR) \
|
||||||
-I$(EXAMPLES_DIR) \
|
-I$(EXAMPLES_DIR) \
|
||||||
-I$(OBJ_DIR)
|
-I$(OBJ_DIR) \
|
||||||
|
-I/usr/include/aarch64-linux-gnu/qt5 \
|
||||||
|
-I/usr/include/aarch64-linux-gnu/qt5/QtCore \
|
||||||
|
-I/usr/include/aarch64-linux-gnu/qt5/QtGui \
|
||||||
|
-I/usr/include/aarch64-linux-gnu/qt5/QtWidgets
|
||||||
|
|
||||||
LIBS = $(VIMBACPP_LIBS) \
|
LIBS = $(VIMBACPP_LIBS) \
|
||||||
$(VIMBAIMAGETRANSFORM_LIBS) \
|
$(VIMBAIMAGETRANSFORM_LIBS) \
|
||||||
$(QTCORE_LIBS) \
|
$(QT_LIBS)
|
||||||
$(QTGUI_LIBS)
|
|
||||||
|
|
||||||
DEFINES =
|
DEFINES =
|
||||||
|
|
||||||
CFLAGS = $(COMMON_CFLAGS) \
|
CFLAGS = $(COMMON_CFLAGS) \
|
||||||
$(VIMBACPP_CFLAGS) \
|
$(VIMBACPP_CFLAGS) \
|
||||||
$(VIMBAIMAGETRANSFORM_CFLAGS) \
|
$(VIMBAIMAGETRANSFORM_CFLAGS) \
|
||||||
$(QTCORE_CFLAGS) \
|
$(QT_CFLAGS)
|
||||||
$(QTGUI_CFLAGS)
|
|
||||||
|
|
||||||
OBJ_FILES = $(OBJ_DIR)/ApiController.o \
|
OBJ_FILES = $(OBJ_DIR)/ApiController.o \
|
||||||
$(OBJ_DIR)/AsynchronousGrab.o \
|
$(OBJ_DIR)/AsynchronousGrab.o \
|
||||||
$(OBJ_DIR)/CameraObserver.o \
|
$(OBJ_DIR)/CameraObserver.o \
|
||||||
$(OBJ_DIR)/FrameObserver.o \
|
$(OBJ_DIR)/FrameObserver.o \
|
||||||
$(OBJ_DIR)/main.o \
|
$(OBJ_DIR)/main.o \
|
||||||
$(OBJ_DIR)/moc_AsynchronousGrab.o \
|
$(OBJ_DIR)/moc_AsynchronousGrab.o \
|
||||||
$(OBJ_DIR)/moc_CameraObserver.o \
|
$(OBJ_DIR)/moc_CameraObserver.o \
|
||||||
$(OBJ_DIR)/moc_FrameObserver.o \
|
$(OBJ_DIR)/moc_FrameObserver.o \
|
||||||
$(OBJ_DIR)/qrc_AsynchronousGrab.o
|
$(OBJ_DIR)/qrc_AsynchronousGrab.o
|
||||||
|
|
||||||
GEN_HEADERS = $(OBJ_DIR)/ui_AsynchronousGrab.h
|
GEN_HEADERS = $(OBJ_DIR)/ui_AsynchronousGrab.h
|
||||||
|
|
||||||
DEPENDENCIES = VimbaCPP \
|
DEPENDENCIES = VimbaCPP \
|
||||||
VimbaImageTransform \
|
VimbaImageTransform
|
||||||
QtCore \
|
|
||||||
QtGui
|
|
||||||
|
|
||||||
$(OBJ_DIR)/moc_%.cpp: $(SOURCE_DIR)/%.h $(OBJ_DIR)
|
$(OBJ_DIR)/moc_%.cpp: $(SOURCE_DIR)/%.h $(OBJ_DIR)
|
||||||
$(MOC) -o $@ $<
|
$(MOC) -o $@ $<
|
||||||
@ -82,3 +90,5 @@ $(OBJ_DIR):
|
|||||||
|
|
||||||
$(BIN_DIR):
|
$(BIN_DIR):
|
||||||
$(MKDIR) -p $(BIN_DIR)
|
$(MKDIR) -p $(BIN_DIR)
|
||||||
|
|
||||||
|
.PHONY: all clean
|
||||||
|
@ -0,0 +1,94 @@
|
|||||||
|
PROJECT_NAME = AsynchronousGrabQt
|
||||||
|
|
||||||
|
PROJECT_DIR = ../..
|
||||||
|
EXAMPLES_DIR = $(PROJECT_DIR)/../..
|
||||||
|
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
|
||||||
|
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
|
||||||
|
|
||||||
|
include $(MAKE_INCLUDE_DIR)/Common.mk
|
||||||
|
|
||||||
|
CONFIG_DIR = $(ARCH)_$(WORDSIZE)bit
|
||||||
|
BIN_FILE = $(PROJECT_NAME)
|
||||||
|
BIN_DIR = binary/$(CONFIG_DIR)
|
||||||
|
OBJ_DIR = object/$(CONFIG_DIR)
|
||||||
|
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
|
||||||
|
|
||||||
|
# Qt 工具路径
|
||||||
|
MOC = /usr/lib/aarch64-linux-gnu/qt5/bin/moc
|
||||||
|
UIC = /usr/lib/aarch64-linux-gnu/qt5/bin/uic
|
||||||
|
RCC = /usr/lib/aarch64-linux-gnu/qt5/bin/rcc
|
||||||
|
|
||||||
|
# 使用 pkg-config 获取 Qt 编译标志
|
||||||
|
QT_CFLAGS := $(shell pkg-config --cflags Qt5Core Qt5Gui Qt5Widgets)
|
||||||
|
QT_LIBS := $(shell pkg-config --libs Qt5Core Qt5Gui Qt5Widgets)
|
||||||
|
|
||||||
|
all: $(BIN_PATH)
|
||||||
|
|
||||||
|
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
|
||||||
|
include $(MAKE_INCLUDE_DIR)/VimbaImageTransform.mk
|
||||||
|
|
||||||
|
SOURCE_DIR = $(PROJECT_DIR)/Source
|
||||||
|
|
||||||
|
INCLUDE_DIRS = -I$(SOURCE_DIR) \
|
||||||
|
-I$(EXAMPLES_DIR) \
|
||||||
|
-I$(OBJ_DIR) \
|
||||||
|
-I/usr/include/aarch64-linux-gnu/qt5 \
|
||||||
|
-I/usr/include/aarch64-linux-gnu/qt5/QtCore \
|
||||||
|
-I/usr/include/aarch64-linux-gnu/qt5/QtGui \
|
||||||
|
-I/usr/include/aarch64-linux-gnu/qt5/QtWidgets
|
||||||
|
|
||||||
|
LIBS = $(VIMBACPP_LIBS) \
|
||||||
|
$(VIMBAIMAGETRANSFORM_LIBS) \
|
||||||
|
$(QT_LIBS)
|
||||||
|
|
||||||
|
DEFINES =
|
||||||
|
|
||||||
|
CFLAGS = $(COMMON_CFLAGS) \
|
||||||
|
$(VIMBACPP_CFLAGS) \
|
||||||
|
$(VIMBAIMAGETRANSFORM_CFLAGS) \
|
||||||
|
$(QT_CFLAGS)
|
||||||
|
|
||||||
|
OBJ_FILES = $(OBJ_DIR)/ApiController.o \
|
||||||
|
$(OBJ_DIR)/AsynchronousGrab.o \
|
||||||
|
$(OBJ_DIR)/CameraObserver.o \
|
||||||
|
$(OBJ_DIR)/FrameObserver.o \
|
||||||
|
$(OBJ_DIR)/main.o \
|
||||||
|
$(OBJ_DIR)/moc_AsynchronousGrab.o \
|
||||||
|
$(OBJ_DIR)/moc_CameraObserver.o \
|
||||||
|
$(OBJ_DIR)/moc_FrameObserver.o \
|
||||||
|
$(OBJ_DIR)/qrc_AsynchronousGrab.o
|
||||||
|
|
||||||
|
GEN_HEADERS = $(OBJ_DIR)/ui_AsynchronousGrab.h
|
||||||
|
|
||||||
|
DEPENDENCIES = VimbaCPP \
|
||||||
|
VimbaImageTransform
|
||||||
|
|
||||||
|
$(OBJ_DIR)/moc_%.cpp: $(SOURCE_DIR)/%.h $(OBJ_DIR)
|
||||||
|
$(MOC) -o $@ $<
|
||||||
|
|
||||||
|
$(OBJ_DIR)/ui_%.h: $(SOURCE_DIR)/res/%.ui $(OBJ_DIR)
|
||||||
|
$(UIC) -o $@ $<
|
||||||
|
|
||||||
|
$(OBJ_DIR)/qrc_%.cpp: $(SOURCE_DIR)/res/%.qrc $(OBJ_DIR)
|
||||||
|
$(RCC) -o $@ $<
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR) $(GEN_HEADERS)
|
||||||
|
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.o: $(OBJ_DIR)/%.cpp $(OBJ_DIR) $(GEN_HEADERS)
|
||||||
|
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(BIN_PATH): $(DEPENDENCIES) $(OBJ_FILES) $(BIN_DIR)
|
||||||
|
$(CXX) $(ARCH_CFLAGS) -o $(BIN_PATH) $(OBJ_FILES) $(LIBS) -Wl,-rpath,'$$ORIGIN'
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) binary -r -f
|
||||||
|
$(RM) object -r -f
|
||||||
|
|
||||||
|
$(OBJ_DIR):
|
||||||
|
$(MKDIR) -p $(OBJ_DIR)
|
||||||
|
|
||||||
|
$(BIN_DIR):
|
||||||
|
$(MKDIR) -p $(BIN_DIR)
|
||||||
|
|
||||||
|
.PHONY: all clean
|
@ -0,0 +1,60 @@
|
|||||||
|
PROJECT_NAME = mako2v4l
|
||||||
|
|
||||||
|
PROJECT_DIR = ../..
|
||||||
|
EXAMPLES_DIR = $(PROJECT_DIR)/../..
|
||||||
|
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
|
||||||
|
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
|
||||||
|
|
||||||
|
include $(MAKE_INCLUDE_DIR)/Common.mk
|
||||||
|
|
||||||
|
CONFIG_DIR = $(ARCH)_$(WORDSIZE)bit
|
||||||
|
BIN_FILE = $(PROJECT_NAME)
|
||||||
|
BIN_DIR = binary/$(CONFIG_DIR)
|
||||||
|
OBJ_DIR = object/$(CONFIG_DIR)
|
||||||
|
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
|
||||||
|
|
||||||
|
all: $(BIN_PATH)
|
||||||
|
|
||||||
|
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
|
||||||
|
include $(MAKE_INCLUDE_DIR)/VimbaImageTransform.mk
|
||||||
|
|
||||||
|
SOURCE_DIR = $(PROJECT_DIR)/Source
|
||||||
|
|
||||||
|
INCLUDE_DIRS = -I$(SOURCE_DIR) \
|
||||||
|
-I$(EXAMPLES_DIR) \
|
||||||
|
-I$(OBJ_DIR) \
|
||||||
|
-I$(VIMBASDK_DIR)/VimbaCPP/Include \
|
||||||
|
-I$(VIMBASDK_DIR)/VimbaImageTransform/Include
|
||||||
|
|
||||||
|
LIBS = $(VIMBACPP_LIBS) \
|
||||||
|
$(VIMBAIMAGETRANSFORM_LIBS) \
|
||||||
|
-lv4l2
|
||||||
|
|
||||||
|
DEFINES =
|
||||||
|
|
||||||
|
CFLAGS = $(COMMON_CFLAGS) \
|
||||||
|
$(VIMBACPP_CFLAGS) \
|
||||||
|
$(VIMBAIMAGETRANSFORM_CFLAGS)
|
||||||
|
|
||||||
|
OBJ_FILES = $(OBJ_DIR)/ApiController.o \
|
||||||
|
$(OBJ_DIR)/FrameObserver.o \
|
||||||
|
$(OBJ_DIR)/main.o
|
||||||
|
|
||||||
|
DEPENDENCIES = VimbaCPP \
|
||||||
|
VimbaImageTransform
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR)
|
||||||
|
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(BIN_PATH): $(DEPENDENCIES) $(OBJ_FILES) $(BIN_DIR)
|
||||||
|
$(CXX) $(ARCH_CFLAGS) -o $(BIN_PATH) $(OBJ_FILES) $(LIBS) -Wl,-rpath,'$ORIGIN'
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) binary -r -f
|
||||||
|
$(RM) object -r -f
|
||||||
|
|
||||||
|
$(OBJ_DIR):
|
||||||
|
$(MKDIR) -p $(OBJ_DIR)
|
||||||
|
|
||||||
|
$(BIN_DIR):
|
||||||
|
$(MKDIR) -p $(BIN_DIR)
|
@ -0,0 +1,173 @@
|
|||||||
|
#include "ApiController.h"
|
||||||
|
#include "FrameObserver.h"
|
||||||
|
#include <sstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace AVT {
|
||||||
|
namespace VmbAPI {
|
||||||
|
namespace Examples {
|
||||||
|
|
||||||
|
ApiController::ApiController()
|
||||||
|
: m_system(VimbaSystem::GetInstance()),
|
||||||
|
m_nWidth(0),
|
||||||
|
m_nHeight(0),
|
||||||
|
m_nPixelFormat(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ApiController::~ApiController()
|
||||||
|
{
|
||||||
|
if (m_pCamera) {
|
||||||
|
StopContinuousImageAcquisition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VmbErrorType ApiController::StartUp()
|
||||||
|
{
|
||||||
|
return m_system.Startup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApiController::ShutDown()
|
||||||
|
{
|
||||||
|
m_system.Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
VmbErrorType ApiController::StartContinuousImageAcquisition(const std::string &rStrCameraID)
|
||||||
|
{
|
||||||
|
VmbErrorType res = m_system.OpenCameraByID(rStrCameraID.c_str(),
|
||||||
|
VmbAccessModeFull,
|
||||||
|
m_pCamera);
|
||||||
|
if (VmbErrorSuccess != res) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adjust packet size for GigE cameras
|
||||||
|
FeaturePtr pCommandFeature;
|
||||||
|
if (VmbErrorSuccess == m_pCamera->GetFeatureByName("GVSPAdjustPacketSize", pCommandFeature)) {
|
||||||
|
res = pCommandFeature->RunCommand();
|
||||||
|
if (VmbErrorSuccess == res) {
|
||||||
|
bool isDone = false;
|
||||||
|
do {
|
||||||
|
res = pCommandFeature->IsCommandDone(isDone);
|
||||||
|
if (VmbErrorSuccess != res) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (!isDone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set camera parameters
|
||||||
|
res = SetValueIntMod2(m_pCamera, "Width", m_nWidth);
|
||||||
|
if (VmbErrorSuccess == res) {
|
||||||
|
res = SetValueIntMod2(m_pCamera, "Height", m_nHeight);
|
||||||
|
}
|
||||||
|
if (VmbErrorSuccess == res) {
|
||||||
|
FeaturePtr pFormatFeature;
|
||||||
|
res = m_pCamera->GetFeatureByName("PixelFormat", pFormatFeature);
|
||||||
|
if (VmbErrorSuccess == res) {
|
||||||
|
res = pFormatFeature->GetValue(m_nPixelFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create frame observer
|
||||||
|
m_pFrameObserver = IFrameObserverPtr(new FrameObserver(m_pCamera));
|
||||||
|
|
||||||
|
// Start acquisition
|
||||||
|
if (VmbErrorSuccess == res) {
|
||||||
|
res = m_pCamera->StartContinuousImageAcquisition(3, m_pFrameObserver);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VmbErrorSuccess != res && m_pCamera) {
|
||||||
|
m_pCamera->Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
VmbErrorType ApiController::StopContinuousImageAcquisition()
|
||||||
|
{
|
||||||
|
if (m_pCamera) {
|
||||||
|
m_pCamera->StopContinuousImageAcquisition();
|
||||||
|
return m_pCamera->Close();
|
||||||
|
}
|
||||||
|
return VmbErrorSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
ApiController::CameraPtrVector ApiController::GetCameraList()
|
||||||
|
{
|
||||||
|
CameraPtrVector cameras;
|
||||||
|
m_system.GetCameras(cameras);
|
||||||
|
return cameras;
|
||||||
|
}
|
||||||
|
|
||||||
|
ApiController::FramePtr ApiController::GetFrame()
|
||||||
|
{
|
||||||
|
return FramePtr();
|
||||||
|
}
|
||||||
|
|
||||||
|
VmbErrorType ApiController::QueueFrame(FramePtr pFrame)
|
||||||
|
{
|
||||||
|
if (!m_pCamera) {
|
||||||
|
return VmbErrorDeviceNotOpen;
|
||||||
|
}
|
||||||
|
return m_pCamera->QueueFrame(pFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApiController::ClearFrameQueue()
|
||||||
|
{
|
||||||
|
// No operation needed as frames are directly streamed to V4L2
|
||||||
|
}
|
||||||
|
|
||||||
|
int ApiController::GetWidth() const {
|
||||||
|
return static_cast<int>(m_nWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ApiController::GetHeight() const {
|
||||||
|
return static_cast<int>(m_nHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
VmbPixelFormatType ApiController::GetPixelFormat() const {
|
||||||
|
return static_cast<VmbPixelFormatType>(m_nPixelFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
double ApiController::GetAverageLatency() const {
|
||||||
|
if (m_pFrameObserver) {
|
||||||
|
FrameObserver* observer = static_cast<FrameObserver*>(m_pFrameObserver.get());
|
||||||
|
if (observer) {
|
||||||
|
return observer->GetAverageLatency();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t ApiController::GetFrameCount() const {
|
||||||
|
if (m_pFrameObserver) {
|
||||||
|
FrameObserver* observer = static_cast<FrameObserver*>(m_pFrameObserver.get());
|
||||||
|
if (observer) {
|
||||||
|
return observer->GetFrameCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
VmbErrorType ApiController::SetValueIntMod2(const AVT::VmbAPI::CameraPtr &camera,
|
||||||
|
const std::string &featureName,
|
||||||
|
VmbInt64_t &storage)
|
||||||
|
{
|
||||||
|
AVT::VmbAPI::FeaturePtr pFeature;
|
||||||
|
VmbInt64_t min = 0, max = 0, inc = 0;
|
||||||
|
|
||||||
|
VmbErrorType res = camera->GetFeatureByName(featureName.c_str(), pFeature);
|
||||||
|
if (VmbErrorSuccess == res) res = pFeature->GetRange(min, max);
|
||||||
|
if (VmbErrorSuccess == res) res = pFeature->GetIncrement(inc);
|
||||||
|
if (VmbErrorSuccess == res) {
|
||||||
|
max = max - (max % inc);
|
||||||
|
if (max % 2 != 0) max -= inc;
|
||||||
|
res = pFeature->SetValue(max);
|
||||||
|
storage = max;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}}} // namespace AVT::VmbAPI::Examples
|
@ -0,0 +1,55 @@
|
|||||||
|
#ifndef APICONTROLLER_H
|
||||||
|
#define APICONTROLLER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <VimbaCPP/Include/VimbaCPP.h>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
namespace AVT {
|
||||||
|
namespace VmbAPI {
|
||||||
|
namespace Examples {
|
||||||
|
|
||||||
|
class FrameObserver;
|
||||||
|
|
||||||
|
class ApiController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef AVT::VmbAPI::CameraPtrVector CameraPtrVector;
|
||||||
|
typedef AVT::VmbAPI::FramePtr FramePtr;
|
||||||
|
|
||||||
|
ApiController();
|
||||||
|
~ApiController();
|
||||||
|
|
||||||
|
VmbErrorType StartUp();
|
||||||
|
void ShutDown();
|
||||||
|
VmbErrorType StartContinuousImageAcquisition(const std::string& cameraID);
|
||||||
|
VmbErrorType StopContinuousImageAcquisition();
|
||||||
|
CameraPtrVector GetCameraList();
|
||||||
|
FramePtr GetFrame();
|
||||||
|
VmbErrorType QueueFrame(FramePtr pFrame);
|
||||||
|
void ClearFrameQueue();
|
||||||
|
|
||||||
|
int GetWidth() const;
|
||||||
|
int GetHeight() const;
|
||||||
|
VmbPixelFormatType GetPixelFormat() const;
|
||||||
|
|
||||||
|
// 新增性能统计方法
|
||||||
|
double GetAverageLatency() const;
|
||||||
|
size_t GetFrameCount() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
AVT::VmbAPI::VimbaSystem& m_system;
|
||||||
|
AVT::VmbAPI::CameraPtr m_pCamera;
|
||||||
|
AVT::VmbAPI::IFrameObserverPtr m_pFrameObserver;
|
||||||
|
VmbInt64_t m_nPixelFormat;
|
||||||
|
VmbInt64_t m_nWidth;
|
||||||
|
VmbInt64_t m_nHeight;
|
||||||
|
|
||||||
|
VmbErrorType SetValueIntMod2(const AVT::VmbAPI::CameraPtr &camera,
|
||||||
|
const std::string &featureName,
|
||||||
|
VmbInt64_t &storage);
|
||||||
|
};
|
||||||
|
|
||||||
|
}}} // namespace AVT::VmbAPI::Examples
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,137 @@
|
|||||||
|
#include "FrameObserver.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
namespace AVT {
|
||||||
|
namespace VmbAPI {
|
||||||
|
namespace Examples {
|
||||||
|
|
||||||
|
FrameObserver::FrameObserver(const CameraPtr& pCamera)
|
||||||
|
: IFrameObserver(pCamera), m_videoFd(-1)
|
||||||
|
{
|
||||||
|
if (!SetupVideoDevice()) {
|
||||||
|
fprintf(stderr, "Failed to setup video device\n");
|
||||||
|
}
|
||||||
|
m_lastFrameTime = std::chrono::high_resolution_clock::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
FrameObserver::~FrameObserver()
|
||||||
|
{
|
||||||
|
CloseVideoDevice();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FrameObserver::SetupVideoDevice()
|
||||||
|
{
|
||||||
|
m_videoFd = open("/dev/video61", O_RDWR | O_NONBLOCK);
|
||||||
|
if (m_videoFd < 0) {
|
||||||
|
perror("Failed to open video device");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&m_vfmt, 0, sizeof(m_vfmt));
|
||||||
|
m_vfmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
|
||||||
|
|
||||||
|
m_vfmt.fmt.pix.width = 640;
|
||||||
|
m_vfmt.fmt.pix.height = 480;
|
||||||
|
m_vfmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
|
||||||
|
m_vfmt.fmt.pix.field = V4L2_FIELD_NONE;
|
||||||
|
|
||||||
|
if (ioctl(m_videoFd, VIDIOC_S_FMT, &m_vfmt) < 0) {
|
||||||
|
perror("Set video format");
|
||||||
|
close(m_videoFd);
|
||||||
|
m_videoFd = -1;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FrameObserver::CloseVideoDevice()
|
||||||
|
{
|
||||||
|
if (m_videoFd >= 0) {
|
||||||
|
close(m_videoFd);
|
||||||
|
m_videoFd = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FrameObserver::UpdateVideoFormat(VmbUint32_t width, VmbUint32_t height, VmbPixelFormatType pixelFormat)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_deviceMutex);
|
||||||
|
|
||||||
|
if (m_vfmt.fmt.pix.width == width &&
|
||||||
|
m_vfmt.fmt.pix.height == height &&
|
||||||
|
m_vfmt.fmt.pix.pixelformat == (pixelFormat == VmbPixelFormatMono8 ? V4L2_PIX_FMT_GREY : V4L2_PIX_FMT_YUYV)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_vfmt.fmt.pix.width = width;
|
||||||
|
m_vfmt.fmt.pix.height = height;
|
||||||
|
|
||||||
|
switch (pixelFormat) {
|
||||||
|
case VmbPixelFormatMono8:
|
||||||
|
m_vfmt.fmt.pix.pixelformat = V4L2_PIX_FMT_GREY;
|
||||||
|
m_vfmt.fmt.pix.sizeimage = width * height;
|
||||||
|
break;
|
||||||
|
case VmbPixelFormatBayerRG8:
|
||||||
|
m_vfmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SRGGB8;
|
||||||
|
m_vfmt.fmt.pix.sizeimage = width * height;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
m_vfmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
|
||||||
|
m_vfmt.fmt.pix.sizeimage = width * height * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ioctl(m_videoFd, VIDIOC_S_FMT, &m_vfmt) < 0) {
|
||||||
|
perror("Update video format");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FrameObserver::FrameReceived(const FramePtr pFrame)
|
||||||
|
{
|
||||||
|
auto startTime = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
VmbUchar_t* pBuffer = nullptr;
|
||||||
|
VmbUint32_t nSize = 0;
|
||||||
|
VmbUint32_t width = 0, height = 0;
|
||||||
|
VmbPixelFormatType pixelFormat;
|
||||||
|
|
||||||
|
if (pFrame->GetImage(pBuffer) != VmbErrorSuccess ||
|
||||||
|
pFrame->GetImageSize(nSize) != VmbErrorSuccess ||
|
||||||
|
pFrame->GetWidth(width) != VmbErrorSuccess ||
|
||||||
|
pFrame->GetHeight(height) != VmbErrorSuccess ||
|
||||||
|
pFrame->GetPixelFormat(pixelFormat) != VmbErrorSuccess) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!UpdateVideoFormat(width, height, pixelFormat)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t written = write(m_videoFd, pBuffer, nSize);
|
||||||
|
if (written != (ssize_t)nSize) {
|
||||||
|
perror("Write to video device");
|
||||||
|
}
|
||||||
|
|
||||||
|
auto endTime = std::chrono::high_resolution_clock::now();
|
||||||
|
double latency = std::chrono::duration<double, std::milli>(endTime - startTime).count();
|
||||||
|
m_totalLatency.store(m_totalLatency.load() + latency);
|
||||||
|
m_frameCount++;
|
||||||
|
|
||||||
|
m_pCamera->QueueFrame(pFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
double FrameObserver::GetAverageLatency() const {
|
||||||
|
return m_frameCount > 0 ? m_totalLatency.load() / m_frameCount : 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t FrameObserver::GetFrameCount() const {
|
||||||
|
return m_frameCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
}}} // namespace AVT::VmbAPI::Examples
|
@ -0,0 +1,43 @@
|
|||||||
|
#ifndef FRAMEOBSERVER_H
|
||||||
|
#define FRAMEOBSERVER_H
|
||||||
|
|
||||||
|
#include <linux/videodev2.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <VimbaCPP/Include/VimbaCPP.h>
|
||||||
|
#include <mutex>
|
||||||
|
#include <chrono>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
namespace AVT {
|
||||||
|
namespace VmbAPI {
|
||||||
|
namespace Examples {
|
||||||
|
|
||||||
|
class FrameObserver : public IFrameObserver
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FrameObserver(const CameraPtr& pCamera);
|
||||||
|
virtual ~FrameObserver();
|
||||||
|
|
||||||
|
void FrameReceived(const FramePtr pFrame) override;
|
||||||
|
|
||||||
|
double GetAverageLatency() const;
|
||||||
|
size_t GetFrameCount() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool SetupVideoDevice();
|
||||||
|
void CloseVideoDevice();
|
||||||
|
bool UpdateVideoFormat(VmbUint32_t width, VmbUint32_t height, VmbPixelFormatType pixelFormat);
|
||||||
|
|
||||||
|
int m_videoFd;
|
||||||
|
struct v4l2_format m_vfmt;
|
||||||
|
std::mutex m_deviceMutex;
|
||||||
|
|
||||||
|
std::atomic<size_t> m_frameCount{0};
|
||||||
|
std::atomic<double> m_totalLatency{0.0};
|
||||||
|
std::chrono::high_resolution_clock::time_point m_lastFrameTime;
|
||||||
|
};
|
||||||
|
|
||||||
|
}}} // namespace AVT::VmbAPI::Examples
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,52 @@
|
|||||||
|
#include "ApiController.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
AVT::VmbAPI::Examples::ApiController controller;
|
||||||
|
|
||||||
|
if (VmbErrorSuccess != controller.StartUp()) {
|
||||||
|
std::cerr << "Failed to start Vimba system" << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto cameras = controller.GetCameraList();
|
||||||
|
if (cameras.empty()) {
|
||||||
|
std::cerr << "No cameras found" << std::endl;
|
||||||
|
controller.ShutDown();
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string cameraId;
|
||||||
|
cameras[0]->GetID(cameraId);
|
||||||
|
std::cout << "Using camera: " << cameraId << std::endl;
|
||||||
|
|
||||||
|
if (VmbErrorSuccess != controller.StartContinuousImageAcquisition(cameraId)) {
|
||||||
|
std::cerr << "Failed to start image acquisition" << std::endl;
|
||||||
|
controller.ShutDown();
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Streaming to V4L2 device. Press Enter to stop..." << std::endl;
|
||||||
|
|
||||||
|
// 定期打印性能统计
|
||||||
|
while (true) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
|
std::cout << "Frames: " << controller.GetFrameCount()
|
||||||
|
<< ", Avg Latency: " << controller.GetAverageLatency() << "ms"
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
// 检查用户输入
|
||||||
|
if (std::cin.rdbuf()->in_avail() > 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
controller.StopContinuousImageAcquisition();
|
||||||
|
controller.ShutDown();
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
@ -0,0 +1,5 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/AsynchronousGrabQt">
|
||||||
|
<file>AsynchronousGrab.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
@ -0,0 +1,111 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>AsynchronousGrabClass</class>
|
||||||
|
<widget class="QMainWindow" name="AsynchronousGrabClass">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>1040</width>
|
||||||
|
<height>780</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>1040</width>
|
||||||
|
<height>780</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>1040</width>
|
||||||
|
<height>780</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>AsynchronousGrab (Qt version)</string>
|
||||||
|
</property>
|
||||||
|
<property name="windowIcon">
|
||||||
|
<iconset resource="AsynchronousGrab.qrc">
|
||||||
|
<normaloff>:/AsynchronousGrabQt/AsynchronousGrab.png</normaloff>:/AsynchronousGrabQt/AsynchronousGrab.png</iconset>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralWidget">
|
||||||
|
<widget class="QListWidget" name="m_ListBoxCameras">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>261</width>
|
||||||
|
<height>491</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QListWidget" name="m_ListLog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>580</y>
|
||||||
|
<width>1041</width>
|
||||||
|
<height>191</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QPushButton" name="m_ButtonStartStop">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>540</y>
|
||||||
|
<width>261</width>
|
||||||
|
<height>31</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Start Image Acquisition</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="m_LabelStream">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>270</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>771</width>
|
||||||
|
<height>561</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QCheckBox" name="m_ColorProcessingCheckBox">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>140</x>
|
||||||
|
<y>510</y>
|
||||||
|
<width>121</width>
|
||||||
|
<height>20</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>ColorProcessing</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
|
<resources>
|
||||||
|
<include location="AsynchronousGrab.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
Reference in New Issue
Block a user