0
我找到一個代碼,它允許您在凸輪上繪製模糊的矩形如何在圖像上繪製模糊的矩形?
我試圖將它從凸輪上的模糊矩形繪製到圖像上,因爲我想在圖像上繪製模糊的矩形。
,這是我的代碼
#include < stdio.h>
#include < iostream>
#include < opencv2\opencv.hpp>
#include < opencv2/core/core.hpp>
#include < opencv2/highgui/highgui.hpp>
#include < opencv2/video/background_segm.hpp>
#include < opencv2\gpu\gpu.hpp>
#include < opencv2\legacy\legacy.hpp>
using namespace std;
using namespace cv;
bool selectObject = false;
Rect selection;
Point origin;
int trackObject = 0;
Mat image;
static void onMouse(int event, int x, int y, int, void*)
{
if (selectObject)
{
selection.x = MIN(x, origin.x);
selection.y = MIN(y, origin.y);
selection.width = std::abs(x - origin.x);
selection.height = std::abs(y - origin.y);
selection &= Rect(0, 0, image.cols, image.rows);
}
switch (event)
{
case CV_EVENT_LBUTTONDOWN:
origin = Point(x, y);
selection = Rect(x, y, 0, 0);
selectObject = true;
break;
case CV_EVENT_LBUTTONUP:
selectObject = false;
if (selection.width > 0 && selection.height > 0)
trackObject = -1;
break;
}
}
int main(void)
{
Mat img;
img = imread("C:/Users/faho0odywbas/Desktop/test.jpg");
Mat frame;
namedWindow("Demo");
setMouseCallback("Demo", onMouse);
for (;;)
{
frame.copyTo(image);
if (selectObject && selection.width > 0 && selection.height > 0)
{
Mat roi(image, selection);
bitwise_not(roi, roi);
printf("%d %d %d %d\n", selection.x, selection.y, selection.width, selection.height);
}
while (1){
imshow("Demo", img);
if (waitKey(10) > 10)
break;
}
}
return 0;
}
和代碼顯示圖像,但我不能借鑑它的矩形!
我想念什麼?
謝謝
非常感謝它的工作原理後,我在代碼的開頭添加的包,但請你可以將這個模糊的矩形到由用戶定義的矩形區域內應使用馬賽克效果模糊的像素。模糊程度取決於用戶指定的值。例如,對於 示例,可以使用整數變量來存儲它: int blur_degree = 5 此處「blur_degree」定義每個Mosaic單位正方形的長度,請參見圖 3.默認情況下,其長度爲5個像素。所以更大的「blur_degree」, 更多模糊的選定區域 –
我建議你開一個新的問題。還建議看看OpenCV官方網站[Q&A](http://answers.opencv.org/) – sturkmen