How the halcon of C++ Qt reads pixel items
This article mainly shows you "C++ Qt halcon how to read pixel project", the content is easy to understand, well-organized, I hope it can help you solve your doubts, the following let the editor lead you to study and learn "C++ Qt halcon how to read pixel project" this article.
Project environment: win10,qt5.14,halcon20
Function: 1. Read the specified image 2. Read the image under the specified directory
Project profile
QT + = core gui greaterThan (QT_MAJOR_VERSION, 4): QT + = widgets CONFIG + = 11 # The following define makes your compiler emit warnings if you use# any Qt feature that has been marked deprecated (the exact warnings# depend on your compiler). Please consult the documentation of the# deprecated API in order to know how to port your code away from it.DEFINES + = QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs.# In order to do so Uncomment the following line.# You can also select to disable deprecated APIs only up to a certain version of Qt.#DEFINES + = QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES + =\ main.cpp\ widget.cpp HEADERS + =\ widget.h # Default rules for deployment.qnx: target.path = / tmp/$$ {TARGET} / binelse: UnixGroupe Android: target.path = / opt/$$ {TARGET} / binbinisEmpty (target.path): INSTALLS + = The include under target # win32 and unix is actually the same win32: {# halcon configuration code Include, Copy lib to the project under LIBS + =-L$$PWD/halcon/win/lib/x64-win64/-lhalcon LIBS + =-L$$PWD/halcon/win/lib/x64-win64/-lhalconc LIBS + =-L$$PWD/halcon/win/lib/x64-win64/-lhalconcpp LIBS + =-L$$PWD/halcon/win/lib/x64-win64/-lhalconcppxl LIBS + =-L$$PWD/halcon/win/lib/x64-win64/-lhalconcxl LIBS + =-L$$PWD/halcon/win/lib/x64-win64/ -lhalconxl LIBS + =-L$$PWD/halcon/win/lib/x64-win64/-lhdevenginecpp LIBS + =-L$$PWD/halcon/win/lib/x64-win64/-lhdevenginecppxl LIBS + =-L$$PWD/halcon/win/lib/x64-win64/-llibiomp5md # INCLUDEPATH + = $$PWD/halcon/win/include # DEPENDPATH + = $$PWD/halcon/win/include INCLUDEPATH + = $$PWD/halcon/linux/include DEPENDPATH + = $PWD/halcon/linux/include} unix: {LIBS + =-L$$PWD/halcon/linux/lib/x64 -linux-lhalcon LIBS + =-L$$PWD/halcon/linux/lib/x64-linux-lhalconc LIBS + =-L$$PWD/halcon/linux/lib/x64-linux-lhalconcpp LIBS + =-L$$PWD/halcon/linux/lib/x64-linux-lhalconcppxl LIBS + =-L$$PWD/halcon/linux/lib/x64-linux/-lhalconcxl LIBS + =-L$$PWD/halcon/linux/lib/x64-linux-lhalconxl LIBS + =-L$$PWD/halcon/linux/lib/x64-linux-lhdevenginecpp LIBS + =-L$$PWD/halcon/linux/lib/ X64-linux-lhdevenginecppxl INCLUDEPATH + = $$PWD/halcon/linux/include DEPENDPATH + = $$PWD/halcon/linux/include}
Header file
# ifndef WIDGET_H#define WIDGET_H# include # include "halconcpp/HalconCpp.h" # include "Halcon.h" using namespace HalconCpp; # pragma execution_character_set ("utf-8") / / supports Chinese class Widget: public QWidget {Q_OBJECT public: Widget (QWidget * parent = nullptr); ~ Widget (); private: QLabel * image_label; HTuple hv_WindowHandle / / HTuple hv_AcqHandle; HObject ho_Image; HTuple hv_Width, hv_Height; / / Hlong windID; Hlong MainWndID; QGroupBox * groupbox1; QRadioButton * radio1; QRadioButton * radio2; QStackedWidget * stackedwidget; QWidget * page1; QWidget * page2; QLineEdit * ledit1; QPushButton * btn1; QLineEdit * ledit2; QPushButton * btn2; QTableWidget * tableWidget; QTableWidgetItem * item0; QString file_path; QStringList filenameList; / / QStringList fullfilename QPushButton * btn3; void create_widget (); void filelist_refresh (); QStringList readfilelist; QString file_name1; QString file_name2; int imageNo=0; / * enum CellType {ct_isUsed,ct_rowNo}; enum FieldColNum {col_isUsed,col_rowNo}; QLabel * labCellIndex; QLabel * labCellType; QLabel * labID; void createItemsARow (bool isUsed,int rowNo,QString FileName) * / private slots: void on_radioButton1_clicked (); void on_radioButton2_clicked (); void on_btn1_clicked (); void on_btn2_clicked (); void on_btn3_clicked (); / / void on_item_clicked (QTableWidgetItem * item); void on_checkchangestate (int, int); / / void slotHeaderClicked (int);}; # endif / / WIDGET_H
C++ file
# include "widget.h" Widget::Widget (QWidget * parent): QWidget (parent) {create_widget (); connect (radio1,SIGNAL (clicked (bool)), this,SLOT (on_radioButton1_clicked (); connect (radio2,SIGNAL (clicked (bool)), this,SLOT (on_radioButton2_clicked (); connect (btn1,SIGNAL (clicked (bool)), this,SLOT (on_btn1_clicked () Connect (btn2,SIGNAL (clicked (bool)), this,SLOT (on_btn2_clicked ()); connect (btn3,SIGNAL (clicked (bool)), this,SLOT (on_btn3_clicked (); connect (tableWidget, SIGNAL (cellClicked (int, int)), this,SLOT (on_checkchangestate (int, int)); / / connect (tableWidget- > horizontalHeader (), SIGNAL (sectionClicked (int)), this,SLOT (slotHeaderClicked (int) } Widget::~Widget () {} void Widget::create_widget () {this- > setFixedSize (916547); this- > setWindowTitle ("image reading"); image_label = new QLabel (this); image_label- > setGeometry (290pl 20611461); MainWndID = (Hlong) this- > image_label- > winId (); SetWindowAttr ("background_color", "gray") / / set the background to gray OpenWindow (0Power0, image_label- > width (), image_label- > height (), MainWndID, "visible", ", & hv_WindowHandle); HDevWindowStack::Push (hv_WindowHandle); groupbox1 = new QGroupBox (this); groupbox1- > setGeometry (10pr 20261121); QLabel * label1 = new QLabel (this- > groupbox1); label1- > setText (" Collection Mode "); label1- > setGeometry (0pl 261L21) Radio1 = new QRadioButton (tr ("specified image"), this- > groupbox1); radio2 = new QRadioButton (tr ("file catalog"), this- > groupbox1); radio1- > setGeometry (50lad 40pint 100pint 20); radio2- > setGeometry (50pint 70pint 100pint 20); radio1- > setChecked (true); stackedwidget = new QStackedWidget (this); stackedwidget- > setGeometry (20160251301); page1 = new QWidget (); QLabel * label2 = new QLabel (page1); label2- > setGeometry (0Jing Jing 100Jue 20) Label2- > setText ("designated Picture"); ledit1 = new QLineEdit (page1); / / ledit1- > setGeometry (30pint 130, 150pct 30); ledit1- > setGeometry (0mai 130pint 200pint 30); ledit1- > setReadOnly (true); btn1 = new QPushButton (page1); btn1- > setGeometry (200pint 130pr 30); btn1- > setIcon (style ()-> standardIcon (QStyle::SP_FileDialogContentsView); page2 = new QWidget (); QLabel * label3 = new QLabel (page2); label3- > setGeometry Label3- > setText ("file catalog"); ledit2 = new QLineEdit (page2); ledit2- > setGeometry (30pc30); btn2 = new QPushButton (page2); btn2- > setGeometry (180lc30); btn2- > setIcon (style ()-> standardIcon (QStyle::SP_FileDialogContentsView)); / / QTableWidget * tableWidget = new QTableWidget (10page2); tableWidget = new QTableWidget (page2); / / QTableWidget * tableWidget = new QTableWidget (page2); tableWidget- > setRowCount (0) TableWidget- > setColumnCount (3); / / page2- > addWidget (); tableWidget- > setGeometry (0Magne70251230); / / tableWidget- > resizeColumnsToContents (); / / tableWidget- > resizeRowsToContents (); / / tableWidget- > setColumnWidth (3200); tableWidget- > setColumnWidth (0Yue50); tableWidget- > setColumnWidth (1JE50); / / tableWidget- > setColumnWidth (2MQ HeaderViewPlux stretch); tableWidget- > setColumnWidth (2120); / / tableWidget- > setRowHeight (3Yuan60); tableWidget- > verticalHeader ()-> setVisible (false) / / hide column headers / / tableWidget- > horizontalHeader ()-> setVisible (false); / / hide row headers tableWidget- > show (); QStringList headerText; headerTextsetDisabled (true); / / set rows can not be dragged / / tableWidget- > setEnabled (false); stackedwidget- > addWidget (page1); stackedwidget- > addWidget (page2); btn3 = new QPushButton (this); btn3- > setGeometry (540, 505, 91, 551); btn3- > setText ("execution") } void Widget::on_radioButton1_clicked () {qDebug ()