///////////////////////////////////////////////////////////////////////////////
// File generated by HDevelop for HALCON/C++ Version 17.12
///////////////////////////////////////////////////////////////////////////////
#ifndef __APPLE__
# include "HalconCpp.h"
# include "HDevThread.h"
# if defined(__linux__) && !defined(__arm__) && !defined(NO_EXPORT_APP_MAIN)
# include <X11/Xlib.h>
# endif
#else
# ifndef HC_LARGE_IMAGES
# include <HALCONCpp/HalconCpp.h>
# include <HALCONCpp/HDevThread.h>
# else
# include <HALCONCppxl/HalconCpp.h>
# include <HALCONCppxl/HDevThread.h>
# endif
# include <stdio.h>
# include <HALCON/HpThread.h>
# include <CoreFoundation/CFRunLoop.h>
#endif
using namespace HalconCpp;
// Procedure declarations
// External procedures
// Chapter: Graphics / Text
// Short Description: This procedure writes a text message.
extern void disp_message (HTuple hv_WindowHandle, HTuple hv_String, HTuple hv_CoordSystem,
HTuple hv_Row, HTuple hv_Column, HTuple hv_Color, HTuple hv_Box);
// Chapter: Graphics / Text
// Short Description: Set font independent of OS
extern void set_display_font (HTuple hv_WindowHandle, HTuple hv_Size, HTuple hv_Font,
HTuple hv_Bold, HTuple hv_Slant);
// Procedures
#ifndef NO_EXPORT_MAIN
// Main procedure
void action()
{
// Local iconic variables
HObject ho_Image, ho_Image1, ho_Image2, ho_Image3;
HObject ho_ImageBinomial, ho_ROI_0, ho_ImageReduced, ho_Regions;
HObject ho_RegionErosion, ho_RegionFillUp, ho_ConnectedRegions;
HObject ho_SelectedRegions, ho_Contour, ho_RightEye, ho_LeftEye;
// Local control variables
HTuple hv_Width, hv_Height, hv_WindowHandle;
HTuple hv_Number, hv_Area, hv_Row, hv_Column, hv_Distance_TwoEye;
HTuple hv_a, hv_b;
if (HDevWindowStack::IsOpen())
CloseWindow(HDevWindowStack::Pop());
ReadImage(&ho_Image, "D:/佳能/2018_03_13/前+左+上光.JPG");
GetImageSize(ho_Image, &hv_Width, &hv_Height);
SetWindowAttr("background_color","black");
OpenWindow(0,0,hv_Width/8,hv_Height/8,0,"visible","",&hv_WindowHandle);
HDevWindowStack::Push(hv_WindowHandle);
if (HDevWindowStack::IsOpen())
DispObj(ho_Image, HDevWindowStack::GetActive());
Decompose3(ho_Image, &ho_Image1, &ho_Image2, &ho_Image3);
BinomialFilter(ho_Image2, &ho_ImageBinomial, 5, 5);
GenRectangle1(&ho_ROI_0, 1355, 2059, 1723, 3000);
ReduceDomain(ho_ImageBinomial, ho_ROI_0, &ho_ImageReduced);
Threshold(ho_ImageReduced, &ho_Regions, 13, 47);
ErosionCircle(ho_Regions, &ho_RegionErosion, 2.5);
FillUp(ho_RegionErosion, &ho_RegionFillUp);
Connection(ho_RegionFillUp, &ho_ConnectedRegions);
SelectShape(ho_ConnectedRegions, &ho_SelectedRegions, "area", "and", 2000, 99999);
CountObj(ho_SelectedRegions, &hv_Number);
if (0 != (hv_Number==2))
{
AreaCenter(ho_SelectedRegions, &hv_Area, &hv_Row, &hv_Column);
//closing_circle (SelectedRegions, RegionOpening, 2.5)
GenContourPolygonXld(&ho_Contour, hv_Row, hv_Column);
hv_Distance_TwoEye = ((((HTuple(hv_Row[0])-HTuple(hv_Row[1]))*(HTuple(hv_Row[0])-HTuple(hv_Row[1])))+((HTuple(hv_Column[0])-HTuple(hv_Column[1]))*(HTuple(hv_Column[0])-HTuple(hv_Column[1])))).TupleSqrt()).TupleInt();
hv_a = ((((HTuple(hv_Row[0])+HTuple(hv_Row[1]))/2)+50)/8).TupleInt();
hv_b = ((HTuple(hv_Column[0])+((HTuple(hv_Column[1])-HTuple(hv_Column[0]))/2))/8).TupleInt();
//人眼区域选择
SelectObj(ho_SelectedRegions, &ho_RightEye, 1);
SelectObj(ho_SelectedRegions, &ho_LeftEye, 2);
if (HDevWindowStack::IsOpen())
ClearWindow(HDevWindowStack::GetActive());
if (HDevWindowStack::IsOpen())
DispObj(ho_Image, HDevWindowStack::GetActive());
if (HDevWindowStack::IsOpen())
SetColor(HDevWindowStack::GetActive(),"blue");
if (HDevWindowStack::IsOpen())
DispObj(ho_RightEye, HDevWindowStack::GetActive());
if (HDevWindowStack::IsOpen())
SetColor(HDevWindowStack::GetActive(),"green");
if (HDevWindowStack::IsOpen())
DispObj(ho_LeftEye, HDevWindowStack::GetActive());
if (HDevWindowStack::IsOpen())
SetColor(HDevWindowStack::GetActive(),"red");
if (HDevWindowStack::IsOpen())
DispObj(ho_Contour, HDevWindowStack::GetActive());
set_display_font(hv_WindowHandle, 18, "mono", "true", "false");
disp_message(hv_WindowHandle, "瞳孔间像素值:"+hv_Distance_TwoEye, "window",
hv_a-160, hv_b-80, "black", "white");
}
}
#ifndef NO_EXPORT_APP_MAIN
#ifdef __APPLE__
// On OS X systems, we must have a CFRunLoop running on the main thread in
// order for the HALCON graphics operators to work correctly, and run the
// action function in a separate thread. A CFRunLoopTimer is used to make sure
// the action function is not called before the CFRunLoop is running.
// Note that starting with macOS 10.12, the run loop may be stopped when a
// window is closed, so we need to put the call to CFRunLoopRun() into a loop
// of its own.
HTuple gStartMutex;
H_pthread_t gActionThread;
HBOOL gTerminate = FALSE;
static void timer_callback(CFRunLoopTimerRef timer, void *info)
{
UnlockMutex(gStartMutex);
}
static Herror apple_action(void **parameters)
{
// Wait until the timer has fired to start processing.
LockMutex(gStartMutex);
UnlockMutex(gStartMutex);
try
{
action();
}
catch (HException &exception)
{
fprintf(stderr," Error #%u in %s: %s\n", exception.ErrorCode(),
(const char *)exception.ProcName(),
(const char *)exception.ErrorMessage());
}
// Tell the main thread to terminate itself.
LockMutex(gStartMutex);
gTerminate = TRUE;
UnlockMutex(gStartMutex);
CFRunLoopStop(CFRunLoopGetMain());
return H_MSG_OK;
}
static int apple_main(int argc, char *argv[])
{
Herror error;
CFRunLoopTimerRef Timer;
CFRunLoopTimerContext TimerContext = { 0, 0, 0, 0, 0 };
CreateMutex("type","sleep",&gStartMutex);
LockMutex(gStartMutex);
error = HpThreadHandleAlloc(&gActionThread);
if (H_MSG_OK != error)
{
fprintf(stderr,"HpThreadHandleAlloc failed: %d\n", error);
exit(1);
}
error = HpThreadCreate(gActionThread,0,apple_action);
if (H_MSG_OK != error)
{
fprintf(stderr,"HpThreadCreate failed: %d\n", error);
exit(1);
}
Timer = CFRunLoopTimerCreate(kCFAllocatorDefault,
CFAbsoluteTimeGetCurrent(),0,0,0,
timer_callback,&TimerContext);
if (!Timer)
{
fprintf(stderr,"CFRunLoopTimerCreate failed\n");
exit(1);
}
CFRunLoopAddTimer(CFRunLoopGetCurrent(),Timer,kCFRunLoopCommonModes);
for (;;)
{
HBOOL terminate;
CFRunLoopRun();
LockMutex(gStartMutex);
terminate = gTerminate;
UnlockMutex(gStartMutex);
if (terminate)
break;
}
CFRunLoopRemoveTimer(CFRunLoopGetCurrent(),Timer,kCFRunLoopCommonModes);
CFRelease(Timer);
error = HpThreadHandleFree(gActionThread);
if (H_MSG_OK != error)
{
fprintf(stderr,"HpThreadHandleFree failed: %d\n", error);
exit(1);
}
ClearMutex(gStartMutex);
return 0;
}
#endif
int main(int argc, char *argv[])
{
int ret = 0;
try
{
#if defined(_WIN32)
SetSystem("use_window_thread", "true");
#elif defined(__linux__) && !defined(__arm__)
XInitThreads();
#endif
// Default settings used in HDevelop (can be omitted)
SetSystem("width", 512);
SetSystem("height", 512);
#ifndef __APPLE__
action();
#else
ret = apple_main(argc,argv);
#endif
}
catch (HException &exception)
{
fprintf(stderr," Error #%u in %s: %s\n", exception.ErrorCode(),
(const char *)exception.ProcName(),
(const char *)exception.ErrorMessage());
ret = 1;
}
return ret;
}
#endif
#endif
人像瞳孔智能测距
需积分: 10 37 浏览量
2018-03-27
14:54:47
上传
评论 1
收藏 6KB ZIP 举报
sztcmx
- 粉丝: 0
- 资源: 1
最新资源
- STM32单片机FPGA毕设电路原理论文报告一种基于st62单片机的称重显示控制器
- STM32单片机FPGA毕设电路原理论文报告一种基于SPCE061A单片机的信号发生器
- Ruby菜鸟入门指南.md
- STM32单片机FPGA毕设电路原理论文报告一种基于PIC系列单片机的SPWM逆变电源
- exp01A.cpp
- Rust语言学习万字指南!.md
- STM32单片机FPGA毕设电路原理论文报告一种基于msp430单片机的心电模块设计
- STM32单片机FPGA毕设电路原理论文报告一种基于MSP430单片机的日程管理系统
- web-screen-capture.jar
- 2024最新计算机二级真题练习题库含答案.md
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈