| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #ifndef __VISIONMEASURECLASS_H__ |
| | | #define __VISIONMEASURECLASS_H__ |
| | | |
| | | #include <iostream> |
| | | #include <string> |
| | | #include <stdio.h> |
| | | |
| | | #ifdef VISIONMEASURE_EXPORTS |
| | | #define EXPORT_MEASURE_EXPORTS _declspec(dllexport) |
| | | #else |
| | | #define EXPORT_MEASURE_EXPORTS _declspec(dllimport) |
| | | #endif |
| | | |
| | | typedef struct _MeasurePoint { |
| | | double x; |
| | | double y; |
| | | double cy; |
| | | }MeasurePoint, *PMeasurePoint; |
| | | |
| | | class EXPORT_MEASURE_EXPORTS CVisionMeasureClass |
| | | { |
| | | public: |
| | | CVisionMeasureClass(); |
| | | ~CVisionMeasureClass(); |
| | | |
| | | public: |
| | | //1. è·åçæ¬å· |
| | | std::string getVersion(void); |
| | | |
| | | //2. æµéç¹ |
| | | int doMeasurePos(unsigned char*img, int width, int height, double x1, double y1, double x2, double y2, double len, int threshold, double *xOutResult, double *yOutResult, double *cyOutResult, double *distOutResult, int &nOutResult); |
| | | |
| | | //3. æµéç¹ |
| | | int doMeasurePosA(unsigned char* img, int width, int height, double sigma, |
| | | MeasurePoint *measureResult1, int &outResult1, |
| | | MeasurePoint* measureResult2, int& outResult2, |
| | | MeasurePoint* measureResult3, int& outResult3, |
| | | MeasurePoint* measureResult4, int& outResult4, |
| | | MeasurePoint* measureResult5, int& outResult5, |
| | | MeasurePoint* measureResult6, int& outResult6, |
| | | MeasurePoint* measureResult7, int& outResult7); |
| | | |
| | | //1. è·åç¨åºè¿è¡è·¯å¾ |
| | | std::string GetAppPathA(void); |
| | | }; |
| | | |
| | | #endif // __VISIONMEASURECLASS_H__ |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #include "stdafx.h" |
| | | #include "BaseProcApi.h" |
| | | |
| | | //对象æ¯å¦åå¨ |
| | | bool ObjectIsExist(HalconCpp::HObject& hObject) { |
| | | /* code */ |
| | | // 夿hObjectæ¯å¦æªåå§å |
| | | if (!hObject.IsInitialized()) return false; |
| | | |
| | | // å建ä¸ä¸ªç©ºçHObject |
| | | HalconCpp::HObject hEmptyObj; |
| | | HalconCpp::GenEmptyObj(&hEmptyObj); |
| | | // 夿hObjectæ¯å¦çäºhEmptyObj |
| | | if (hObject == hEmptyObj) return false; |
| | | |
| | | // å¦åè¿åtrue |
| | | return true; |
| | | } |
| | | |
| | | bool GetImageSizeApi(HalconCpp::HObject hImage, int& width, int& height) { |
| | | /*c ode */ |
| | | if (!ObjectIsExist(hImage)) return false; |
| | | |
| | | HalconCpp::HTuple hWidth, hHeight; |
| | | HalconCpp::GetImageSize(hImage, &hWidth, &hHeight); |
| | | width = hWidth[0].I(); |
| | | height = hHeight[0].I(); |
| | | if (width < 1 || height < 1) return false; |
| | | return true; |
| | | } |
| | | |
| | | int doMeasurePosApi(HalconCpp::HObject& hImage, double x1, double y1, double x2, double y2, double len, int threshold, double sigma, double* xOutResult, double* yOutResult, double* cyOutResult, double* distOutResult, int& nOutResult) { |
| | | /* code */ |
| | | int width = 0; |
| | | int height = 0; |
| | | nOutResult = 0; |
| | | if (!GetImageSizeApi(hImage, width, height)) return -1; |
| | | if (width < 1 || height < 1) return -1; |
| | | |
| | | // Local control variables |
| | | HalconCpp::HTuple hv_AmplitudeThreshold, hv_RoiWidthLen2; |
| | | HalconCpp::HTuple hv_LineRowStart_Measure_01_0, hv_LineColumnStart_Measure_01_0; |
| | | HalconCpp::HTuple hv_LineRowEnd_Measure_01_0, hv_LineColumnEnd_Measure_01_0; |
| | | HalconCpp::HTuple hv_TmpCtrl_Row, hv_TmpCtrl_Column, hv_TmpCtrl_Dr; |
| | | HalconCpp::HTuple hv_TmpCtrl_Dc, hv_TmpCtrl_Phi, hv_TmpCtrl_Len1; |
| | | HalconCpp::HTuple hv_TmpCtrl_Len2, hv_MsrHandle_Measure_01_0, hv_Row_Measure_01_0; |
| | | HalconCpp::HTuple hv_Column_Measure_01_0, hv_Amplitude_Measure_01_0; |
| | | HalconCpp::HTuple hv_Distance_Measure_01_0; |
| | | |
| | | hv_AmplitudeThreshold = threshold; |
| | | hv_RoiWidthLen2 = len; |
| | | |
| | | //Measure 01: Coordinates for line Measure 01 [0] |
| | | hv_LineRowStart_Measure_01_0 = y1; |
| | | hv_LineColumnStart_Measure_01_0 = x1; |
| | | hv_LineRowEnd_Measure_01_0 = y2; |
| | | hv_LineColumnEnd_Measure_01_0 = x2; |
| | | |
| | | //Measure 01: Convert coordinates to rectangle2 type |
| | | hv_TmpCtrl_Row = 0.5 * (hv_LineRowStart_Measure_01_0 + hv_LineRowEnd_Measure_01_0); |
| | | hv_TmpCtrl_Column = 0.5 * (hv_LineColumnStart_Measure_01_0 + hv_LineColumnEnd_Measure_01_0); |
| | | hv_TmpCtrl_Dr = hv_LineRowStart_Measure_01_0 - hv_LineRowEnd_Measure_01_0; |
| | | hv_TmpCtrl_Dc = hv_LineColumnEnd_Measure_01_0 - hv_LineColumnStart_Measure_01_0; |
| | | hv_TmpCtrl_Phi = hv_TmpCtrl_Dr.TupleAtan2(hv_TmpCtrl_Dc); |
| | | hv_TmpCtrl_Len1 = 0.5 * (((hv_TmpCtrl_Dr * hv_TmpCtrl_Dr) + (hv_TmpCtrl_Dc * hv_TmpCtrl_Dc)).TupleSqrt()); |
| | | hv_TmpCtrl_Len2 = hv_RoiWidthLen2; |
| | | double len1 = hv_TmpCtrl_Len1[0].D(); |
| | | double len2 = hv_TmpCtrl_Len2[0].D(); |
| | | printf("len1 = %f, len2 = %f\n", len1, len2); |
| | | |
| | | //Measure 01: Create measure for line Measure 01 [0] |
| | | //Measure 01: Attention: This assumes all images have the same size! |
| | | HalconCpp::GenMeasureRectangle2(hv_TmpCtrl_Row, hv_TmpCtrl_Column, hv_TmpCtrl_Phi, hv_TmpCtrl_Len1, |
| | | hv_TmpCtrl_Len2, width, height, "nearest_neighbor", &hv_MsrHandle_Measure_01_0); |
| | | //Measure 01: *************************************************************** |
| | | //Measure 01: * The code which follows is to be executed once / measurement * |
| | | //Measure 01: *************************************************************** |
| | | //Measure 01: The image is assumed to be made available in the |
| | | //Measure 01: variable last displayed in the graphics window |
| | | //Measure 01: Execute measurements |
| | | HalconCpp::MeasurePos(hImage, hv_MsrHandle_Measure_01_0, sigma, hv_AmplitudeThreshold, "all", |
| | | "all", &hv_Row_Measure_01_0, &hv_Column_Measure_01_0, &hv_Amplitude_Measure_01_0, |
| | | &hv_Distance_Measure_01_0); |
| | | //Measure 01: Do something with the results |
| | | HalconCpp::CloseMeasure(hv_MsrHandle_Measure_01_0); |
| | | |
| | | HalconCpp::HTuple hv_length = hv_Row_Measure_01_0.TupleLength(); |
| | | int count = hv_length[0].I(); |
| | | if (count > MEASURE_MAX_NUM) { |
| | | count = MEASURE_MAX_NUM; |
| | | } |
| | | |
| | | for (int i = 0; i < count; i++) { |
| | | xOutResult[i] = hv_Column_Measure_01_0[i].D(); |
| | | yOutResult[i] = hv_Row_Measure_01_0[i].D(); |
| | | cyOutResult[i] = hv_Amplitude_Measure_01_0[i].D(); |
| | | } |
| | | int num = count - 1; |
| | | for (int i = 0; i < num; i++) { |
| | | distOutResult[i] = hv_Distance_Measure_01_0[i].D(); |
| | | } |
| | | |
| | | nOutResult = count; |
| | | |
| | | return 1; |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #ifndef BASEPROCAPI_H |
| | | #define BASEPROCAPI_H |
| | | |
| | | #include <HalconCpp.h> |
| | | |
| | | #define VERSION_NO "1.0.0" |
| | | #define MEASURE_MAX_NUM 100 |
| | | |
| | | int doMeasurePosApi(HalconCpp::HObject& hImage, double x1, double y1, double x2, double y2, double len, int threshold, double sigma, double* xOutResult, double* yOutResult, double* cyOutResult, double* distOutResult, int& nOutResult); |
| | | |
| | | #endif |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | ======================================================================== |
| | | 卿龿¥åºï¼VisionMeasure é¡¹ç®æ¦è¿° |
| | | ======================================================================== |
| | | |
| | | åºç¨ç¨åºå导已为æ¨åå»ºäºæ¤ VisionMeasure DLLã |
| | | |
| | | æ¬æä»¶æ¦è¦ä»ç»ç»æ VisionMeasure åºç¨ç¨åºçæ¯ä¸ªæä»¶çå
容ã |
| | | |
| | | |
| | | VisionMeasure.vcxproj |
| | | è¿æ¯ä½¿ç¨åºç¨ç¨åºå导çæç VC++ 项ç®çä¸»é¡¹ç®æä»¶ï¼å
¶ä¸å
å«çæè¯¥æä»¶ç Visual C++ ççæ¬ä¿¡æ¯ï¼ä»¥åæå
³ä½¿ç¨åºç¨ç¨åºå坼鿩çå¹³å°ãé
ç½®å项ç®åè½çä¿¡æ¯ã |
| | | |
| | | VisionMeasure.vcxproj.filters |
| | | è¿æ¯ä½¿ç¨âåºç¨ç¨åºå导âçæç VC++ 项ç®çé卿件ãå®å
嫿å
³é¡¹ç®æä»¶ä¸çéå¨ä¹é´çå
³èä¿¡æ¯ãå¨ IDE ä¸ï¼éè¿è¿ç§å
³èï¼å¨ç¹å®èç¹ä¸ä»¥åç»å½¢å¼æ¾ç¤ºå
·æç¸ä¼¼æ©å±åçæä»¶ãä¾å¦ï¼â.cppâæä»¶ä¸âæºæä»¶âçéå¨å
³èã |
| | | |
| | | VisionMeasure.cpp |
| | | è¿æ¯ä¸» DLL æºæä»¶ã |
| | | |
| | | æ¤ DLL å¨å建æ¶ä¸å¯¼åºä»»ä½ç¬¦å·ãå æ¤ï¼çææ¶ä¸ä¼äº§ç .lib æä»¶ã妿叿æ¤é¡¹ç®æä¸ºå
¶ä»æä¸ªé¡¹ç®ç项ç®ä¾èµé¡¹ï¼åéè¦æ·»å 代ç ä»¥ä» DLL å¯¼åºæäºç¬¦å·ï¼ä»¥ä¾¿äº§çä¸ä¸ªå¯¼åºåºï¼æè
ï¼ä¹å¯ä»¥å¨é¡¹ç®â屿§é¡µâå¯¹è¯æ¡ä¸çâ龿¥å¨âæä»¶å¤¹ä¸ï¼å°â常è§â屿§é¡µä¸çâ忽ç¥è¾å
¥åºâ屿§è®¾ç½®ä¸ºâæ¯âã |
| | | |
| | | ///////////////////////////////////////////////////////////////////////////// |
| | | å
¶ä»æ åæä»¶: |
| | | |
| | | StdAfx.h, StdAfx.cpp |
| | | è¿äºæä»¶ç¨äºçæå为 VisionMeasure.pch çé¢ç¼è¯å¤´ (PCH) æä»¶åå为 StdAfx.obj çé¢ç¼è¯ç±»åæä»¶ã |
| | | |
| | | ///////////////////////////////////////////////////////////////////////////// |
| | | å
¶ä»æ³¨é: |
| | | |
| | | åºç¨ç¨åºå导使ç¨âTODO:âæ³¨éæ¥æç¤ºåºæ·»å æèªå®ä¹çæºä»£ç é¨åã |
| | | |
| | | ///////////////////////////////////////////////////////////////////////////// |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | // VisionMeasure.cpp : å®ä¹ DLL åºç¨ç¨åºç导åºå½æ°ã |
| | | // |
| | | |
| | | #include "stdafx.h" |
| | | |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="utf-8"?> |
| | | <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| | | <ItemGroup Label="ProjectConfigurations"> |
| | | <ProjectConfiguration Include="Debug|Win32"> |
| | | <Configuration>Debug</Configuration> |
| | | <Platform>Win32</Platform> |
| | | </ProjectConfiguration> |
| | | <ProjectConfiguration Include="Release|Win32"> |
| | | <Configuration>Release</Configuration> |
| | | <Platform>Win32</Platform> |
| | | </ProjectConfiguration> |
| | | <ProjectConfiguration Include="Debug|x64"> |
| | | <Configuration>Debug</Configuration> |
| | | <Platform>x64</Platform> |
| | | </ProjectConfiguration> |
| | | <ProjectConfiguration Include="Release|x64"> |
| | | <Configuration>Release</Configuration> |
| | | <Platform>x64</Platform> |
| | | </ProjectConfiguration> |
| | | </ItemGroup> |
| | | <PropertyGroup Label="Globals"> |
| | | <ProjectGuid>{52480DCD-7CDE-4608-B432-1DF92C6F29D6}</ProjectGuid> |
| | | <Keyword>Win32Proj</Keyword> |
| | | <RootNamespace>VisionMeasure</RootNamespace> |
| | | <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion> |
| | | </PropertyGroup> |
| | | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> |
| | | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> |
| | | <ConfigurationType>DynamicLibrary</ConfigurationType> |
| | | <UseDebugLibraries>true</UseDebugLibraries> |
| | | <PlatformToolset>v140</PlatformToolset> |
| | | <CharacterSet>Unicode</CharacterSet> |
| | | </PropertyGroup> |
| | | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> |
| | | <ConfigurationType>DynamicLibrary</ConfigurationType> |
| | | <UseDebugLibraries>false</UseDebugLibraries> |
| | | <PlatformToolset>v140</PlatformToolset> |
| | | <WholeProgramOptimization>true</WholeProgramOptimization> |
| | | <CharacterSet>Unicode</CharacterSet> |
| | | </PropertyGroup> |
| | | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> |
| | | <ConfigurationType>DynamicLibrary</ConfigurationType> |
| | | <UseDebugLibraries>true</UseDebugLibraries> |
| | | <PlatformToolset>v140</PlatformToolset> |
| | | <CharacterSet>Unicode</CharacterSet> |
| | | </PropertyGroup> |
| | | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> |
| | | <ConfigurationType>DynamicLibrary</ConfigurationType> |
| | | <UseDebugLibraries>false</UseDebugLibraries> |
| | | <PlatformToolset>v140</PlatformToolset> |
| | | <WholeProgramOptimization>true</WholeProgramOptimization> |
| | | <CharacterSet>Unicode</CharacterSet> |
| | | </PropertyGroup> |
| | | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> |
| | | <ImportGroup Label="ExtensionSettings"> |
| | | </ImportGroup> |
| | | <ImportGroup Label="Shared"> |
| | | </ImportGroup> |
| | | <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
| | | <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
| | | </ImportGroup> |
| | | <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
| | | <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
| | | </ImportGroup> |
| | | <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
| | | <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
| | | </ImportGroup> |
| | | <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
| | | <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
| | | </ImportGroup> |
| | | <PropertyGroup Label="UserMacros" /> |
| | | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
| | | <LinkIncremental>true</LinkIncremental> |
| | | </PropertyGroup> |
| | | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
| | | <LinkIncremental>true</LinkIncremental> |
| | | </PropertyGroup> |
| | | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
| | | <LinkIncremental>false</LinkIncremental> |
| | | </PropertyGroup> |
| | | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
| | | <LinkIncremental>false</LinkIncremental> |
| | | </PropertyGroup> |
| | | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
| | | <ClCompile> |
| | | <PrecompiledHeader>Use</PrecompiledHeader> |
| | | <WarningLevel>Level3</WarningLevel> |
| | | <Optimization>Disabled</Optimization> |
| | | <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;VISIONMEASURE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
| | | <SDLCheck>true</SDLCheck> |
| | | </ClCompile> |
| | | <Link> |
| | | <SubSystem>Windows</SubSystem> |
| | | <GenerateDebugInformation>true</GenerateDebugInformation> |
| | | </Link> |
| | | </ItemDefinitionGroup> |
| | | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
| | | <ClCompile> |
| | | <PrecompiledHeader>Use</PrecompiledHeader> |
| | | <WarningLevel>Level3</WarningLevel> |
| | | <Optimization>Disabled</Optimization> |
| | | <PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;VISIONMEASURE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
| | | <SDLCheck>true</SDLCheck> |
| | | <AdditionalIncludeDirectories>$(HALCONROOT)\include\halconcpp;$(HALCONROOT)\include</AdditionalIncludeDirectories> |
| | | </ClCompile> |
| | | <Link> |
| | | <SubSystem>Windows</SubSystem> |
| | | <GenerateDebugInformation>true</GenerateDebugInformation> |
| | | <AdditionalLibraryDirectories>$(HALCONROOT)\lib\$(HALCONARCH)</AdditionalLibraryDirectories> |
| | | <AdditionalDependencies>halconcpp.lib;%(AdditionalDependencies)</AdditionalDependencies> |
| | | </Link> |
| | | <PostBuildEvent> |
| | | <Command>copy "$(TargetDir)$(ProjectName).lib" "$(SolutionDir)VisionLib\lib\$(Configuration)\$(ProjectName).lib" |
| | | copy "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)VisionLib\lib\$(Configuration)\$(ProjectName).dll" |
| | | copy "$(TargetDir)$(ProjectName).pdb" "$(SolutionDir)VisionLib\lib\$(Configuration)\$(ProjectName).pdb" |
| | | copy "$(SolutionDir)$(ProjectName)\VisionMeasureClass.h" "$(SolutionDir)VisionLib\include\VisionMeasureClass.h"</Command> |
| | | </PostBuildEvent> |
| | | </ItemDefinitionGroup> |
| | | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
| | | <ClCompile> |
| | | <WarningLevel>Level3</WarningLevel> |
| | | <PrecompiledHeader>Use</PrecompiledHeader> |
| | | <Optimization>MaxSpeed</Optimization> |
| | | <FunctionLevelLinking>true</FunctionLevelLinking> |
| | | <IntrinsicFunctions>true</IntrinsicFunctions> |
| | | <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;VISIONMEASURE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
| | | <SDLCheck>true</SDLCheck> |
| | | </ClCompile> |
| | | <Link> |
| | | <SubSystem>Windows</SubSystem> |
| | | <GenerateDebugInformation>true</GenerateDebugInformation> |
| | | <EnableCOMDATFolding>true</EnableCOMDATFolding> |
| | | <OptimizeReferences>true</OptimizeReferences> |
| | | </Link> |
| | | </ItemDefinitionGroup> |
| | | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
| | | <ClCompile> |
| | | <WarningLevel>Level3</WarningLevel> |
| | | <PrecompiledHeader>Use</PrecompiledHeader> |
| | | <Optimization>MaxSpeed</Optimization> |
| | | <FunctionLevelLinking>true</FunctionLevelLinking> |
| | | <IntrinsicFunctions>true</IntrinsicFunctions> |
| | | <PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;VISIONMEASURE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
| | | <SDLCheck>true</SDLCheck> |
| | | <AdditionalIncludeDirectories>$(HALCONROOT)\include\halconcpp;$(HALCONROOT)\include</AdditionalIncludeDirectories> |
| | | </ClCompile> |
| | | <Link> |
| | | <SubSystem>Windows</SubSystem> |
| | | <GenerateDebugInformation>true</GenerateDebugInformation> |
| | | <EnableCOMDATFolding>true</EnableCOMDATFolding> |
| | | <OptimizeReferences>true</OptimizeReferences> |
| | | <AdditionalLibraryDirectories>$(HALCONROOT)\lib\$(HALCONARCH)</AdditionalLibraryDirectories> |
| | | <AdditionalDependencies>halconcpp.lib;%(AdditionalDependencies)</AdditionalDependencies> |
| | | </Link> |
| | | <PostBuildEvent> |
| | | <Command>copy "$(TargetDir)$(ProjectName).lib" "$(SolutionDir)SDK\VisionMeasure\lib\$(Configuration)\$(ProjectName).lib" |
| | | copy "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)SDK\VisionMeasure\lib\$(Configuration)\$(ProjectName).dll" |
| | | copy "$(TargetDir)$(ProjectName).pdb" "$(SolutionDir)SDK\VisionMeasure\lib\$(Configuration)\$(ProjectName).pdb" |
| | | copy "$(SolutionDir)$(ProjectName)\VisionMeasureClass.h" "$(SolutionDir)SDK\VisionMeasure\include\VisionMeasureClass.h"</Command> |
| | | </PostBuildEvent> |
| | | </ItemDefinitionGroup> |
| | | <ItemGroup> |
| | | <Text Include="ReadMe.txt" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ClInclude Include="BaseProcApi.h" /> |
| | | <ClInclude Include="stdafx.h" /> |
| | | <ClInclude Include="targetver.h" /> |
| | | <ClInclude Include="VisionMeasureClass.h" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ClCompile Include="BaseProcApi.cpp" /> |
| | | <ClCompile Include="dllmain.cpp"> |
| | | <CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</CompileAsManaged> |
| | | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
| | | </PrecompiledHeader> |
| | | <CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</CompileAsManaged> |
| | | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
| | | </PrecompiledHeader> |
| | | <CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</CompileAsManaged> |
| | | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
| | | </PrecompiledHeader> |
| | | <CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</CompileAsManaged> |
| | | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
| | | </PrecompiledHeader> |
| | | </ClCompile> |
| | | <ClCompile Include="stdafx.cpp"> |
| | | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> |
| | | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> |
| | | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> |
| | | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> |
| | | </ClCompile> |
| | | <ClCompile Include="VisionMeasure.cpp" /> |
| | | <ClCompile Include="VisionMeasureClass.cpp" /> |
| | | </ItemGroup> |
| | | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |
| | | <ImportGroup Label="ExtensionTargets"> |
| | | </ImportGroup> |
| | | </Project> |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="utf-8"?> |
| | | <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| | | <ItemGroup> |
| | | <Filter Include="æºæä»¶"> |
| | | <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> |
| | | <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> |
| | | </Filter> |
| | | <Filter Include="头æä»¶"> |
| | | <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> |
| | | <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> |
| | | </Filter> |
| | | <Filter Include="èµæºæä»¶"> |
| | | <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> |
| | | <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> |
| | | </Filter> |
| | | <Filter Include="include"> |
| | | <UniqueIdentifier>{24a6b585-160d-499d-9942-34dd0fc03439}</UniqueIdentifier> |
| | | </Filter> |
| | | <Filter Include="sdk"> |
| | | <UniqueIdentifier>{fcd811cc-88b7-49b8-9003-fc8a96e0b2c1}</UniqueIdentifier> |
| | | </Filter> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <Text Include="ReadMe.txt" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ClInclude Include="stdafx.h"> |
| | | <Filter>头æä»¶</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="targetver.h"> |
| | | <Filter>头æä»¶</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="BaseProcApi.h"> |
| | | <Filter>include</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="VisionMeasureClass.h"> |
| | | <Filter>sdk</Filter> |
| | | </ClInclude> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ClCompile Include="stdafx.cpp"> |
| | | <Filter>æºæä»¶</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="dllmain.cpp"> |
| | | <Filter>æºæä»¶</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="VisionMeasureClass.cpp"> |
| | | <Filter>include</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="BaseProcApi.cpp"> |
| | | <Filter>include</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="VisionMeasure.cpp"> |
| | | <Filter>æºæä»¶</Filter> |
| | | </ClCompile> |
| | | </ItemGroup> |
| | | </Project> |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #include "stdafx.h" |
| | | #include "VisionMeasureClass.h" |
| | | #include "BaseProcApi.h" |
| | | |
| | | CVisionMeasureClass::CVisionMeasureClass() { |
| | | /* code */ |
| | | |
| | | } |
| | | |
| | | CVisionMeasureClass::~CVisionMeasureClass() { |
| | | /* code */ |
| | | |
| | | } |
| | | |
| | | std::string CVisionMeasureClass::getVersion(void) { |
| | | /* code */ |
| | | return VERSION_NO; |
| | | } |
| | | |
| | | int CVisionMeasureClass::doMeasurePos(unsigned char* img, int width, int height, double x1, double y1, double x2, double y2, double len, int threshold, double* xOutResult, double* yOutResult, double* cyOutResult, double* distOutResult, int& nOutResult) { |
| | | /* code */ |
| | | if (nullptr == img) return -1; |
| | | if (width < 1 || height < 1) return -1; |
| | | |
| | | try { |
| | | HalconCpp::HObject hImage; |
| | | HalconCpp::GenImage1(&hImage, "byte", width, height, (Hlong)img); |
| | | |
| | | int nRet = doMeasurePosApi(hImage, x1, y1, x2, y2, len, threshold, 1.0f, xOutResult, yOutResult, cyOutResult, distOutResult, nOutResult); |
| | | hImage.Clear(); |
| | | return nRet; |
| | | } |
| | | catch (...) { |
| | | return -1; |
| | | } |
| | | |
| | | } |
| | | |
| | | int CVisionMeasureClass::doMeasurePosA(unsigned char* img, int width, int height, double sigma, |
| | | MeasurePoint* measureResult1, int& outResult1, |
| | | MeasurePoint* measureResult2, int& outResult2, |
| | | MeasurePoint* measureResult3, int& outResult3, |
| | | MeasurePoint* measureResult4, int& outResult4, |
| | | MeasurePoint* measureResult5, int& outResult5, |
| | | MeasurePoint* measureResult6, int& outResult6, |
| | | MeasurePoint* measureResult7, int& outResult7) { |
| | | /* code */ |
| | | if (nullptr == img) return -1; |
| | | |
| | | HalconCpp::HObject hImage, hZoomImage, hMeanImage; |
| | | HalconCpp::GenImage1(&hImage, "byte", width, height, (Hlong)img); |
| | | int szHeight = (int)(0.5 * height); |
| | | HalconCpp::ZoomImageSize(hImage, &hZoomImage, width, szHeight, "constant"); |
| | | HalconCpp::MeanImage(hZoomImage, &hMeanImage, 1, 5); |
| | | |
| | | |
| | | double xOutResult[MEASURE_MAX_NUM] = { 0 }; |
| | | double yOutResult[MEASURE_MAX_NUM] = { 0 }; |
| | | double cyOutResult[MEASURE_MAX_NUM] = { 0 }; |
| | | double distOutResult[MEASURE_MAX_NUM] = { 0 }; |
| | | int outNum = 0; |
| | | |
| | | int topEdge = 15; |
| | | int botEdge = szHeight - 16; |
| | | int step = (int)((botEdge - topEdge) / 6); |
| | | int x1 = 5; |
| | | int x2 = width - 6; |
| | | for (int i = 0; i < 7; i++) { |
| | | int y1 = topEdge + i * step; |
| | | int y2 = y1; |
| | | int threshold = 10; |
| | | doMeasurePosApi(hMeanImage, x1, y1, x2, y2, 10, threshold, sigma, xOutResult, yOutResult, cyOutResult, distOutResult, outNum); |
| | | if (0 == i) { |
| | | outResult1 = outNum; |
| | | for (int i = 0; i < outNum; i++) { |
| | | measureResult1[i].x = xOutResult[i]; |
| | | measureResult1[i].y = 2 * yOutResult[i]; |
| | | measureResult1[i].cy = cyOutResult[i]; |
| | | } |
| | | } |
| | | else if (1 == i) { |
| | | outResult2 = outNum; |
| | | for (int i = 0; i < outNum; i++) { |
| | | measureResult2[i].x = xOutResult[i]; |
| | | measureResult2[i].y = 2 * yOutResult[i]; |
| | | measureResult2[i].cy = cyOutResult[i]; |
| | | } |
| | | } |
| | | else if (2 == i) { |
| | | outResult3 = outNum; |
| | | for (int i = 0; i < outNum; i++) { |
| | | measureResult3[i].x = xOutResult[i]; |
| | | measureResult3[i].y = 2 * yOutResult[i]; |
| | | measureResult3[i].cy = cyOutResult[i]; |
| | | } |
| | | } |
| | | else if (3 == i) { |
| | | outResult4 = outNum; |
| | | for (int i = 0; i < outNum; i++) { |
| | | measureResult4[i].x = xOutResult[i]; |
| | | measureResult4[i].y = 2 * yOutResult[i]; |
| | | measureResult4[i].cy = cyOutResult[i]; |
| | | } |
| | | } |
| | | else if (4 == i) { |
| | | outResult5 = outNum; |
| | | for (int i = 0; i < outNum; i++) { |
| | | measureResult5[i].x = xOutResult[i]; |
| | | measureResult5[i].y = 2 * yOutResult[i]; |
| | | measureResult5[i].cy = cyOutResult[i]; |
| | | } |
| | | } |
| | | else if (5 == i) { |
| | | outResult6 = outNum; |
| | | for (int i = 0; i < outNum; i++) { |
| | | measureResult6[i].x = xOutResult[i]; |
| | | measureResult6[i].y = 2 * yOutResult[i]; |
| | | measureResult6[i].cy = cyOutResult[i]; |
| | | } |
| | | } |
| | | else if (6 == i) { |
| | | outResult7 = outNum; |
| | | for (int i = 0; i < outNum; i++) { |
| | | measureResult7[i].x = xOutResult[i]; |
| | | measureResult7[i].y = 2 * yOutResult[i]; |
| | | measureResult7[i].cy = cyOutResult[i]; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | std::string CVisionMeasureClass::GetAppPathA(void) { |
| | | /* code */ |
| | | char szFilePath[MAX_PATH] = { 0 }, szDrive[MAX_PATH] = { 0 }, szDir[MAX_PATH] = { 0 }, szFileName[MAX_PATH] = { 0 }, szExt[MAX_PATH] = { 0 }; |
| | | GetModuleFileNameA(NULL, szFilePath, sizeof(szFilePath)); |
| | | _splitpath_s(szFilePath, szDrive, szDir, szFileName, szExt); |
| | | |
| | | std::string str(szDrive); |
| | | str.append(szDir); |
| | | return str; |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #ifndef __VISIONMEASURECLASS_H__ |
| | | #define __VISIONMEASURECLASS_H__ |
| | | |
| | | #include <iostream> |
| | | #include <string> |
| | | #include <stdio.h> |
| | | |
| | | #ifdef VISIONMEASURE_EXPORTS |
| | | #define EXPORT_MEASURE_EXPORTS _declspec(dllexport) |
| | | #else |
| | | #define EXPORT_MEASURE_EXPORTS _declspec(dllimport) |
| | | #endif |
| | | |
| | | typedef struct _MeasurePoint { |
| | | double x; |
| | | double y; |
| | | double cy; |
| | | }MeasurePoint, *PMeasurePoint; |
| | | |
| | | class EXPORT_MEASURE_EXPORTS CVisionMeasureClass |
| | | { |
| | | public: |
| | | CVisionMeasureClass(); |
| | | ~CVisionMeasureClass(); |
| | | |
| | | public: |
| | | //1. è·åçæ¬å· |
| | | std::string getVersion(void); |
| | | |
| | | //2. æµéç¹ |
| | | int doMeasurePos(unsigned char*img, int width, int height, double x1, double y1, double x2, double y2, double len, int threshold, double *xOutResult, double *yOutResult, double *cyOutResult, double *distOutResult, int &nOutResult); |
| | | |
| | | //3. æµéç¹ |
| | | int doMeasurePosA(unsigned char* img, int width, int height, double sigma, |
| | | MeasurePoint *measureResult1, int &outResult1, |
| | | MeasurePoint* measureResult2, int& outResult2, |
| | | MeasurePoint* measureResult3, int& outResult3, |
| | | MeasurePoint* measureResult4, int& outResult4, |
| | | MeasurePoint* measureResult5, int& outResult5, |
| | | MeasurePoint* measureResult6, int& outResult6, |
| | | MeasurePoint* measureResult7, int& outResult7); |
| | | |
| | | //1. è·åç¨åºè¿è¡è·¯å¾ |
| | | std::string GetAppPathA(void); |
| | | }; |
| | | |
| | | #endif // __VISIONMEASURECLASS_H__ |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | // dllmain.cpp : å®ä¹ DLL åºç¨ç¨åºçå
¥å£ç¹ã |
| | | #include "stdafx.h" |
| | | |
| | | BOOL APIENTRY DllMain( HMODULE hModule, |
| | | DWORD ul_reason_for_call, |
| | | LPVOID lpReserved |
| | | ) |
| | | { |
| | | switch (ul_reason_for_call) |
| | | { |
| | | case DLL_PROCESS_ATTACH: |
| | | case DLL_THREAD_ATTACH: |
| | | case DLL_THREAD_DETACH: |
| | | case DLL_PROCESS_DETACH: |
| | | break; |
| | | } |
| | | return TRUE; |
| | | } |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | // stdafx.cpp : åªå
æ¬æ åå
å«æä»¶çæºæä»¶ |
| | | // VisionMeasure.pch å°ä½ä¸ºé¢ç¼è¯å¤´ |
| | | // stdafx.obj å°å
å«é¢ç¼è¯ç±»åä¿¡æ¯ |
| | | |
| | | #include "stdafx.h" |
| | | |
| | | // TODO: å¨ STDAFX.H ä¸å¼ç¨ä»»ä½æéçéå 头æä»¶ï¼ |
| | | //è䏿¯å¨æ¤æä»¶ä¸å¼ç¨ |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | // stdafx.h : æ åç³»ç»å
嫿件çå
å«æä»¶ï¼ |
| | | // ææ¯ç»å¸¸ä½¿ç¨ä½ä¸å¸¸æ´æ¹ç |
| | | // ç¹å®äºé¡¹ç®çå
嫿件 |
| | | // |
| | | |
| | | #pragma once |
| | | |
| | | #include "targetver.h" |
| | | |
| | | #define WIN32_LEAN_AND_MEAN // ä» Windows 头䏿餿å°ä½¿ç¨çèµæ |
| | | // Windows 头æä»¶: |
| | | #include <windows.h> |
| | | |
| | | |
| | | |
| | | // TODO: 卿¤å¤å¼ç¨ç¨åºéè¦çå
¶ä»å¤´æä»¶ |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #pragma once |
| | | |
| | | // å
æ¬ SDKDDKVer.h å°å®ä¹å¯ç¨çæé«çæ¬ç Windows å¹³å°ã |
| | | |
| | | // 妿è¦ä¸ºä»¥åç Windows å¹³å°çæåºç¨ç¨åºï¼è¯·å
æ¬ WinSDKVer.hï¼å¹¶å° |
| | | // å° _WIN32_WINNT å®è®¾ç½®ä¸ºè¦æ¯æçå¹³å°ï¼ç¶ååå
æ¬ SDKDDKVer.hã |
| | | |
| | | #include <SDKDDKVer.h> |