opencv+python 畫bounding-box


c++:

printf("nbox:%d\n",nboxes);
const char *pFileName = "E:\\process_img\\boundingbox\\1.txt";
FILE * pFile;
pFile = fopen(pFileName, "a");
if (NULL == pFile)
{
printf("error");
return;
}
for (int i = 0; i < nboxes; ++i) {
l_int32 x, y, width, height;
boxaGetBoxGeometry(*boxes, i, &x, &y, &width, &height);
printf("%d %d %d %d\n", x, y, width, height);
fprintf(pFile, "%d %d %d %d\n", x, y, width, height);
}

fclose(pFile);

 

 

 

import cv2 as cv
import numpy as np

img_path='E:/process_img/boundingbox/'
img_name='12_extra_non_hlines.jpg'
pts='E:/process_img/boundingbox/temp1.txt'
src=cv.imread(img_path+img_name)#src是numpy.ndarray類型
bounding_box=np.loadtxt(pts,dtype=np.int32)
# cv.imshow('ori_src',src)
for line in bounding_box:
pt1=(line[0],line[1])
pt2 = (line[0]+line[2], line[1]+line[3])
cv.rectangle(src,pt1,pt2,(0,255,255))

cv.imshow('bounding_box',src)
cv.imwrite(img_path+'bounding_box.jpg',src)
cv.waitKey(0)
cv.destroyAllWindows()

數據:

15 12 2 26
15 60 2 25
15 107 2 25
15 154 2 25
504 157 2 20
15 249 2 25
15 296 2 4
15 301 2 20
300 342 2 26
15 343 2 25
15 390 2 10
275 390 2 10
15 401 2 15
275 401 2 13
15 438 2 25
15 485 2 15
15 501 2 6
292 530 1 21
15 532 2 26
15 579 2 21
275 579 2 21
15 601 2 4
275 601 2 2
15 627 2 25
15 674 2 25
59 725 2 19
15 771 2 23
15 816 2 25
15 863 2 25


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM