日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

opencv 裁剪 java_OpenCV绘制轮廓和裁剪

發(fā)布時(shí)間:2024/10/8 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 opencv 裁剪 java_OpenCV绘制轮廓和裁剪 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我是OpenCV的新手 . 首先,將物體放在白紙上,然后使用機(jī)器人相機(jī)拍攝照片 . 在下一步,我試圖使用OpenCV(找到輪廓和繪制輪廓)提取放在白紙上的對(duì)象 . 我想將這個(gè)對(duì)象用于我的機(jī)器人項(xiàng)目 .

示例圖片:

這是我試過的代碼:

int main(int argc, char* argv[]){

int largest_area=0;

int largest_contour_index=0;

Rect bounding_rect;

// read the file from console

Mat img0 = imread(argv[1], 1);

Mat img1;

cvtColor(img0, img1, CV_RGB2GRAY);

// Canny filter

Canny(img1, img1, 100, 200);

// find the contours

vector< vector > contours;

findContours(img1, contours, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);

printf("%ld\n", contours.size());

for( size_t i = 0; i< contours.size(); i++ ) // iterate through each contour.

{

double area = contourArea(contours[i]); // Find the area of contour

if(area > largest_area)

{

largest_area = area;

largest_contour_index = i; //Store the index of largest contour

bounding_rect = boundingRect(contours[i]); // Find the bounding rectangle for biggest contour

}

}

cout << "contour " << contours.size() << endl;

cout << "largest contour " << largest_contour_index << endl;

Scalar color = Scalar(0,0,255);

drawContours(img0, contours, -1, color);

Mat roi = Mat(img0, bounding_rect);

// show the images

imshow("result", img0);

imshow("roi",roi);

imwrite("result.png",roi);

waitKey();

return 0;

}

這將為照片中的所有對(duì)象繪制輪廓 . 但是如何才能在白紙上提取物體?例如在這張圖片中:

我只想從圖像裁剪卡,但我不知道如何繼續(xù) . 誰(shuí)能幫我嗎?

總結(jié)

以上是生活随笔為你收集整理的opencv 裁剪 java_OpenCV绘制轮廓和裁剪的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。