Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions adcvApp/Db/NDCV.template
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion adcvApp/adcvSrc/NDPluginCV.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
57 changes: 57 additions & 0 deletions adcvApp/adcvSrc/NDPluginCVHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Point2f> srcPoints;
vector<Point2f> 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<int>(inputs[8]);
int height = static_cast<int>(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
//-------------------------------------------------

Expand Down Expand Up @@ -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
* ----------------------- */

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 9 additions & 5 deletions adcvApp/adcvSrc/NDPluginCVHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down