diff --git a/adcvApp/Db/NDCV.template b/adcvApp/Db/NDCV.template index 0917df9..75a10a3 100644 --- a/adcvApp/Db/NDCV.template +++ b/adcvApp/Db/NDCV.template @@ -83,6 +83,8 @@ record(mbbo, "$(P)$(R)CompVisionFunction2") field(THVL, "3") field(FRST, "Log Scaling") field(FRVL, "4") + field(FVST, "Warp Perspective") + field(FVVL, "5") field(VAL, "0") info(autosaveFields, "VAL") } @@ -101,6 +103,8 @@ record(mbbi, "$(P)$(R)CompVisionFunction2_RBV") field(THVL, "3") field(FRST, "Log Scaling") field(FRVL, "4") + field(FVST, "Warp Perspective") + field(FVVL, "5") field(VAL, "0") field(SCAN, "I/O Intr") } diff --git a/adcvApp/adcvSrc/NDPluginCV.h b/adcvApp/adcvSrc/NDPluginCV.h index f440203..4e7ab52 100644 --- a/adcvApp/adcvSrc/NDPluginCV.h +++ b/adcvApp/adcvSrc/NDPluginCV.h @@ -32,7 +32,7 @@ using namespace cv; // version numbers #define NDPluginCV_VERSION 1 -#define NDPluginCV_REVISION 2 +#define NDPluginCV_REVISION 5 #define NDPluginCV_MODIFICATION 0 /* Definitions of parameters */ diff --git a/adcvApp/adcvSrc/NDPluginCVHelper.cpp b/adcvApp/adcvSrc/NDPluginCVHelper.cpp index a13cd9c..bc20ee9 100644 --- a/adcvApp/adcvSrc/NDPluginCVHelper.cpp +++ b/adcvApp/adcvSrc/NDPluginCVHelper.cpp @@ -974,6 +974,34 @@ ADCVStatus_t NDPluginCVHelper::log_scaling(Mat& img, double* inputs, double* out return status; } + +ADCVStatus_t NDPluginCVHelper::warp_perspective(Mat& img, double* inputs, double* outputs) { + vector srcPoints; + vector dstPoints; + const char* functionName = "warp_perspective"; + ADCVStatus_t status = cvHelperSuccess; + srcPoints.push_back(Point2f(inputs[0], inputs[1])); + srcPoints.push_back(Point2f(inputs[2], inputs[3])); + srcPoints.push_back(Point2f(inputs[4], inputs[5])); + srcPoints.push_back(Point2f(inputs[6], inputs[7])); + + int width = static_cast(inputs[8]); + int height = static_cast(inputs[9]); + dstPoints.push_back(Point2f(0, 0)); + dstPoints.push_back(Point2f(width - 1, 0)); + dstPoints.push_back(Point2f(width - 1, height - 1)); + dstPoints.push_back(Point2f(0, height - 1)); + + try { + Mat perspectiveMatrix = getPerspectiveTransform(srcPoints, dstPoints); + warpPerspective(img, img, perspectiveMatrix, Size(width, height)); + cvHelperStatus = "Finished computing warped image"; + } catch (Exception& e) { + print_cv_error(e, functionName); + status = cvHelperError; + } +} + //------------------------ End of OpenCV wrapper functions //------------------------------------------------- @@ -1464,6 +1492,29 @@ ADCVStatus_t NDPluginCVHelper::get_log_scaling_description(string* inputDesc, st populate_remaining_descriptions(inputDesc, outputDesc, numInput, numOutput); return status; } + +ADCVStatus_t NDPluginCVHelper::get_warp_perspective_description(string* inputDesc, + string* outputDesc, + string* description) { + ADCVStatus_t status = cvHelperSuccess; + int numInput = 10; + int numOutput = 0; + inputDesc[0] = "X1"; + inputDesc[1] = "Y1"; + inputDesc[2] = "X2"; + inputDesc[3] = "Y2"; + inputDesc[4] = "X3"; + inputDesc[5] = "Y3"; + inputDesc[6] = "X4"; + inputDesc[7] = "Y4"; + inputDesc[8] = "Output Width"; + inputDesc[9] = "Output Height"; + *description = "Apply perspective warp to image based on source and destination points"; + populate_remaining_descriptions(inputDesc, outputDesc, numInput, numOutput); + return status; +} + + /* ---------------------- Functions called from the EPICS Plugin implementation * ----------------------- */ @@ -1510,6 +1561,9 @@ ADCVStatus_t NDPluginCVHelper::processImage(Mat& image, ADCVFunction_t function, case ADCV_LogScaling: status = log_scaling(image, inputs, outputs); break; + case ADCV_WarpPerspective: + status = warp_perspective(image, inputs, outputs); + break; case ADCV_Sharpen: status = downscale_image_8bit(image, camera_depth); status = sharpen_images(image, inputs, outputs); @@ -1598,6 +1652,9 @@ ADCVStatus_t NDPluginCVHelper::getFunctionDescription(ADCVFunction_t function, s case ADCV_LogScaling: status = get_log_scaling_description(inputDesc, outputDesc, description); break; + case ADCV_WarpPerspective: + status = get_warp_perspective_description(inputDesc, outputDesc, description); + break; /* case ADCV_MovementVectors: status = get_movement_vectors_description(inputDesc, outputDesc, description); diff --git a/adcvApp/adcvSrc/NDPluginCVHelper.h b/adcvApp/adcvSrc/NDPluginCVHelper.h index a6db1da..cbc5b0e 100644 --- a/adcvApp/adcvSrc/NDPluginCVHelper.h +++ b/adcvApp/adcvSrc/NDPluginCVHelper.h @@ -58,7 +58,7 @@ using namespace std; * */ #define N_FUNC_1 7 -#define N_FUNC_2 5 +#define N_FUNC_2 6 #define N_FUNC_3 5 // Total Number of CV functions @@ -78,10 +78,11 @@ typedef enum { ADCV_Sharpen = 8, ADCV_ConvertFormat = 9, ADCV_LogScaling = 10, - ADCV_UserDefined = 11, - ADCV_ImageStats = 12, - ADCV_DistanceCheck = 13, - ADCV_VideoRecord = 14, + ADCV_WarpPerspective = 11, + ADCV_UserDefined = 12, + ADCV_ImageStats = 13, + ADCV_DistanceCheck = 14, + ADCV_VideoRecord = 15, } ADCVFunction_t; // enum that stores file save format @@ -147,6 +148,7 @@ class NDPluginCVHelper { ADCVStatus_t convert_image_format(Mat& img, double* inputs, double* outputs); ADCVStatus_t video_record(Mat& img, double* inputs, double* outputs); ADCVStatus_t log_scaling(Mat& img, double* inputs, double* outputs); + ADCVStatus_t warp_perspective(Mat& img, double* inputs, double* outputs); // under development ADCVStatus_t movement_vectors(Mat& img, double* inputs, double* outputs); @@ -183,6 +185,8 @@ class NDPluginCVHelper { string* description); ADCVStatus_t get_log_scaling_description(string* inputDesc, string* outputDesc, string* description); + ADCVStatus_t get_warp_perspective_description(string* inputDesc, string* outputDesc, + string* description); // Under development ADCVStatus_t get_movement_vectors_description(string* inputDesc, string* outputDesc,