本文整理汇总了C++中cvDrawContours函数的典型用法代码示例。如果您正苦于以下问题:C++ cvDrawContours函数的具体用法?C++ cvDrawContours怎么用?C++ cvDrawContours使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cvDrawContours函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: preprocess
IplImage* preprocess(IplImage* img){ //creates a Image with the contours in the picture
CvMemStorage* g_storage = NULL;
IplImage* gray;
gray = cvCreateImage( cvGetSize( img ), 8, 1 ); //creates the immage, allocating memory for the pixel values
g_storage = cvCreateMemStorage(0);
cvClearMemStorage( g_storage );
CvSeq* contours = 0;
cvCvtColor( img, gray, CV_BGR2GRAY );
cvThreshold( gray, gray, 100, 255, CV_THRESH_BINARY );
cvFindContours( gray, g_storage, &contours ); //find the contours with the thresholdimmage
cvZero( gray );
if( contours )
{
cvDrawContours(gray,contours,cvScalarAll(255),cvScalarAll(255),100 ); //paint the contours on immage contours
}
return gray;
}
开发者ID:fatma-meawad,项目名称:food-recognition-project,代码行数:17,代码来源:breathing.cpp
示例2: main
int main(int argc, char **argv)
{
int thresh = 128;
int erode = 0;
int dilate = 0;
int do_contour = 0;
IplImage *image_bw = cvCreateImage(SIZE, 8, 1);
IplImage *image_thresh = cvCreateImage(SIZE, 8, 1);
IplImage *image_temp = cvCreateImage(SIZE, 8, 1);
cvNamedWindow("config", CV_WINDOW_AUTOSIZE);
cvCreateTrackbar("threshold", "config", &thresh, 255, NULL);
cvCreateTrackbar("erode", "config", &erode, 10, NULL);
cvCreateTrackbar("dilate", "config", &dilate, 10, NULL);
cvCreateTrackbar("contour", "config", &do_contour, 1, NULL);
CvMemStorage *storage = cvCreateMemStorage();
while (cvWaitKey(10) < 0) {
IplImage *image = freenect_sync_get_rgb_cv(0);
if (!image) {
printf("Error: Kinect not connected?\n");
return -1;
}
cvCvtColor(image, image, CV_RGB2BGR);
cvCvtColor(image, image_bw, CV_RGB2GRAY);
cvThreshold(image_bw, image_thresh, thresh, 255, CV_THRESH_BINARY);
cvErode(image_thresh, image_thresh, NULL, erode);
cvDilate(image_thresh, image_thresh, NULL, dilate);
if (do_contour) {
CvSeq *contours;
cvCopy(image_thresh, image_temp);
cvFindContours(image_temp, storage, &contours);
cvDrawContours(image, contours, CV_RGB(0, 255, 0), CV_RGB(0, 255, 255), 1);
}
cvShowImage("RGB", image);
cvShowImage("BW", image_bw);
cvShowImage("THRESH", image_thresh);
}
return 0;
}
开发者ID:egradman,项目名称:cv-workshop,代码行数:46,代码来源:contours.cpp
示例3: node_composit_exec_cvDrawContour
static void node_composit_exec_cvDrawContour(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
IplImage *img, *dst, *img1, *img2, *img3,*imgRed, *umbral;
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* contour = 0;
//TODO: Use atach buffers
if(out[0]->hasoutput==0) return;
img=in[0]->data;
dst = cvCreateImage( cvGetSize(img), 8, 3 );
img1=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
img2=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
img3=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
imgRed=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
umbral=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
cvSplit(img, img1, img2, imgRed, img3);
cvThreshold( umbral,imgRed,210,255, CV_THRESH_BINARY );
cvFindContours( img, storage, &contour, sizeof(CvContour),CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE,cvPoint(0, 0) );
cvZero( dst );
for( ; contour != 0; contour = contour->h_next )
{
CvScalar color = CV_RGB( rand()&255, rand()&255, rand()&255 );
/* replace CV_FILLED with 1 to see the outlines */
cvDrawContours( dst, contour, color, color, -1, CV_FILLED, 8, cvPoint(0,0) );
}
out[0]->data= dst;
/*CvSeq* contour = in[1]->data;
if(in[0]->data && in[1]->data){
IplImage* dst = cvCreateImage( cvGetSize(image), 8, 3 );
cvZero(dst);
//cvDrawContours( dst, contour, CV_RGB(255,0,0),CV_RGB(0,255,0), -1,3, CV_AA,cvPoint(0,0));
CvSeq* c=contour;
for( ; c != 0; c = c->h_next )
{
CvScalar color = CV_RGB( rand()&255, rand()&255, rand()&255 );
cvDrawContours( dst, c, color, color, -1, 1, 8 ,cvPoint(0,0));
}
out[0]->data= dst;
}*/
}
开发者ID:BHCLL,项目名称:blendocv,代码行数:45,代码来源:CMP_CvDrawContour.c
示例4: cvGetMat
CvSeq*cvSegmentFGMask(CvArr* _mask, int poly1Hull0, float perimScale, CvMemStorage* storage, CvPoint offset)
{
CvMat mstub, *mask = cvGetMat(_mask, &mstub);
CvMemStorage* tempStorage = storage ? storage : cvCreateMemStorage();
CvSeq *contours, *c;
int nContours = 0;
CvContourScanner scanner;
// clean up raw mask
cvMorphologyEx(mask, mask, 0, 0, CV_MOP_OPEN, 1);
cvMorphologyEx(mask, mask, 0, 0, CV_MOP_CLOSE, 1);
// find contours around only bigger regions
scanner = cvStartFindContours(mask, tempStorage,
sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, offset);
while ((c = cvFindNextContour(scanner)) != 0)
{
double len = cvContourPerimeter(c);
double q = (mask->rows + mask->cols) / perimScale; // calculate perimeter len threshold
if (len < q) //Get rid of blob if it's perimeter is too small
cvSubstituteContour(scanner, 0);
else //Smooth it's edges if it's large enough
{
CvSeq* newC;
if (poly1Hull0) //Polygonal approximation of the segmentation
newC = cvApproxPoly(c, sizeof(CvContour), tempStorage, CV_POLY_APPROX_DP, 2, 0);
else //Convex Hull of the segmentation
newC = cvConvexHull2(c, tempStorage, CV_CLOCKWISE, 1);
cvSubstituteContour(scanner, newC);
nContours++;
}
}
contours = cvEndFindContours(&scanner);
// paint the found regions back into the image
cvZero(mask);
for (c = contours; c != 0; c = c->h_next)
cvDrawContours(mask, c, cvScalarAll(255), cvScalarAll(0), -1, CV_FILLED, 8,
cvPoint(-offset.x, -offset.y));
if (tempStorage != storage)
{
cvReleaseMemStorage(&tempStorage);
contours = 0;
}
return contours;
}
开发者ID:Doufang,项目名称:PistonRing,代码行数:45,代码来源:CameraPublic.cpp
示例5: cvCreateMemStorage
void moBlobFinderModule::applyFilter(IplImage *src) {
this->storage = cvCreateMemStorage(0);
this->clearBlobs();
this->storage = cvCreateMemStorage(0);
cvCopy(src, this->output_buffer);
CvSeq *contours = 0;
cvFindContours(this->output_buffer, this->storage, &contours, sizeof(CvContour), CV_RETR_CCOMP);
cvDrawContours(this->output_buffer, contours, cvScalarAll(255), cvScalarAll(255), 100);
// Consider each contour a blob and extract the blob infos from it.
int size;
int ratio;
int min_size = this->property("min_size").asInteger();
int max_size = this->property("max_size").asInteger();
CvSeq *cur_cont = contours;
while (cur_cont != 0) {
CvRect rect = cvBoundingRect(cur_cont, 0);
size = rect.width * rect.height;
// Check ratio to make sure blob can physically represent a finger
// magic number 6 is used for now to represent maximum ratio of
// Length/thickness of finger
if (rect.width < rect.height) {
ratio = rect.height / (double)rect.width;
} else {
ratio = rect.width / (double)rect.height;
}
if ((ratio <= 6) && (size >= min_size) && (size <= max_size)) {
moDataGenericContainer *blob = new moDataGenericContainer();
blob->properties["implements"] = new moProperty("pos,size");
blob->properties["x"] = new moProperty((rect.x + rect.width / 2) / (double) src->width);
blob->properties["y"] = new moProperty((rect.y + rect.height / 2) / (double) src->height);
blob->properties["width"] = new moProperty(rect.width);
blob->properties["height"] = new moProperty(rect.height);
this->blobs->push_back(blob);
cvRectangle(this->output_buffer, cvPoint(rect.x,rect.y), cvPoint(rect.x + rect.width,rect.x + rect.height), cvScalar(250,10,10), 1);
}
cur_cont = cur_cont->h_next;
}
cvReleaseMemStorage(&this->storage);
this->output_data->push(this->blobs);
}
开发者ID:arasbm,项目名称:Movid,代码行数:44,代码来源:moBlobFinderModule.cpp
示例6: main
int main()
{
const int imgHeight = 500;
const int imgWidth = 500;
IplImage* pImgSrc = cvCreateImage(cvSize(imgWidth, imgHeight), IPL_DEPTH_8U, 1); // Ôʼͼ
IplImage* pImgContour = NULL; // ÂÖÀªÍ¼
CvMemStorage* pMemStorage = cvCreateMemStorage(0); // ÁÙʱ´æ´¢Çø
CvSeq* pContour = 0; // ´æ´¢ÂÖÀªµã
// »æÖÆÔʼͼƬ
DrawImage(pImgSrc);
// ÏÔʾÔʼͼ
cvNamedWindow("Source", CV_WINDOW_AUTOSIZE);
cvShowImage("Source", pImgSrc);
// ΪÂÖÀªÍ¼ÉêÇë¿Õ¼ä, 3ͨµÀͼÏñ
pImgContour = cvCreateImage(cvGetSize(pImgSrc), IPL_DEPTH_8U, 3);
// ½«µ¥Í¨µÀ»Ò¶Èͼת»¯Îª3ͨµÀ»Ò¶Èͼ
//cvCvtColor(pImgSrc, pImgContour, CV_GRAY2BGR);
cvZero(pImgContour);
// ²éÕÒÂÖÀª
cvFindContours(pImgSrc, pMemStorage, &pContour, sizeof(CvContour), CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));
// ½«ÂÖÀª»³ö
cvDrawContours(pImgContour, pContour, CV_RGB(0, 0, 255), CV_RGB(255, 0, 0), 2, 2, 8, cvPoint(0, 0));
// ÏÔʾÂÖÀªÍ¼
cvNamedWindow("Contour", CV_WINDOW_AUTOSIZE);
cvShowImage("Contour", pImgContour);
cvWaitKey(0);
cvDestroyWindow("Contour");
cvDestroyWindow("Source");
cvReleaseImage(&pImgSrc);
cvReleaseImage(&pImgContour);
cvReleaseMemStorage(&pMemStorage);
return 0;
}
开发者ID:BurnellLiu,项目名称:LiuProject,代码行数:44,代码来源:main.cpp
示例7: startTracking
void MeanShift::startTracking(const Image* image, const CvConnectedComp* cComp)
{
if (!cComp->contour) /* Not really connected component */
return startTracking(image, cComp->rect);
Image* mask = new Image(image->size(), UByte, 1);
cvDrawContours(mask->cvImage(),
cComp->contour,
cvScalar(255),
cvScalar(255),
-1,
CV_FILLED,
8);
delete m_trackingHist;
m_trackingHist = Histogram::createHSHistogram(image, mask);
m_lastPostition = cComp->rect;
delete mask;
}
开发者ID:endSly,项目名称:CVTrackpad,代码行数:19,代码来源:MeanShift.cpp
示例8: contour
IplImage* contour(IplImage* img)
{
static int i;
char fileName[20];
CvMemStorage* store;
IplImage* aux=NULL;
if(aux == NULL)
{
aux = cvCreateImage(cvGetSize(img),8,1);
store = cvCreateMemStorage(0);
}
CvSeq * contours =0;
cvFindContours(img,store,&contours); //finding contours in an image
cvZero(aux);
//if(contours->total)
{
cvDrawContours(aux,contours,cvScalarAll(255),cvScalarAll(255),100);
}
CvMoments *moments = (CvMoments*)malloc(sizeof(CvMoments));
double M00, M01, M10;
fruitCount=0;
while(contours!=NULL) //detects the moments means coords of individual contours
{
if( cvContourArea(contours,CV_WHOLE_SEQ) < 5 ) //detects only sizable objects
{
contours = contours->h_next;
continue;
}
cvMoments(contours, moments);
M00 = cvGetSpatialMoment(moments,0,0);
M10 = cvGetSpatialMoment(moments,1,0);
M01 = cvGetSpatialMoment(moments,0,1);
centers[fruitCount].x = (int)(M10/M00); //global variable, stores the centre coords of an object
centers[fruitCount].y = (int)(M01/M00);
fruitCount++; //important global variable, it represents the total no. of objects detected in the image if it is zero the no action :)
contours = contours->h_next;
}
cvClearMemStorage(store);
return aux;
}
开发者ID:devbhave,项目名称:bot-harvest,代码行数:42,代码来源:cutterController.cpp
示例9: malloc
/*
* Prints a contour on a dst Image. Used for debugging.
* prints text at the side of a contour.
* depthLevel sets the level in the contour tree(to include/exclue holes)
*/
void Contours::printContour(int depthLevel, CvScalar color,IplImage * dst){
CvFont font;
int line_type=CV_AA;
char * a=(char *) malloc(20);
char * b=(char *) malloc(20);
char * c=(char *) malloc(20);
char * d=(char *) malloc(20);
char * e=(char *) malloc(20);
cvDrawContours( dst, this->c, CV_RGB(255,0,0), CV_RGB(0,255,0),
depthLevel, 3, CV_AA, cvPoint(0,0) );
CvMemStorage* mem = cvCreateMemStorage(0);
CvBox2D box=cvMinAreaRect2(this->c,mem);
//~ traversePoints(this->c);
std::vector<int> centroid=this->getCentroid();
CvPoint pt2=cvPoint(centroid[0]+5,centroid[1]+5);
CvPoint pt3=cvPoint(centroid[0]+5,centroid[1]+15);
CvPoint pt4=cvPoint(centroid[0]+5,centroid[1]+25);
CvPoint pt5=cvPoint(centroid[0]+5,centroid[1]+35);
CvPoint pt6=cvPoint(centroid[0]+5,centroid[1]+45);
sprintf(a,"per: %g",this->getPerimeter());
sprintf(b,"zone: %d",getPointZone(this->x,this->y));
sprintf(c,"area: %g",this->getArea());
sprintf(d,"ecc: %g",this->getPerimeter()*this->getPerimeter()/this->getArea());
//~ sprintf(d,"boxArea: %g",(double) this->getArea()/(box.size.width*box.size.height));
cvInitFont( &font, CV_FONT_HERSHEY_COMPLEX, 0.5, 0.5, 0.0,0.5, line_type );
cvPutText( dst, a, pt2, &font, CV_RGB(255,255,0));
cvPutText( dst, c, pt3, &font, CV_RGB(255,255,0));
cvPutText( dst, b, pt4, &font, CV_RGB(255,255,0));
cvPutText( dst, d, pt5, &font, CV_RGB(255,255,0));
//~ free(a);
cvReleaseMemStorage(&mem);
}
开发者ID:margguo,项目名称:tpf-robotica,代码行数:47,代码来源:Contours.cpp
示例10: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
CvSeq* contours = NULL;
CvMemStorage* storage = cvCreateMemStorage(0);
IplImage* img = cvLoadImage("answer_reveal.png");
cvNamedWindow("win");
IplImage* grayImg = cvCreateImage(cvGetSize(img), 8, 1);
cvCvtColor(img, grayImg, CV_RGB2GRAY);
cvThreshold(grayImg, grayImg, 160, 255, CV_THRESH_BINARY);
cvFindContours(grayImg, storage, &contours);
// cvZero(grayImg); -- if we were displaying the gray image with the contours, in only black and white
if (contours) {
cvDrawContours(img, contours,
cvScalar(255, 0, 0), // ext color (red)
cvScalar(0, 255, 0), // hole color (green)
100, // max level of contours to draw
5); // thickness
}
cvShowImage("win", img);
// experiment to read a frame from an image
CvCapture* capture = cvCaptureFromFile("C:\\Projects\\meancat\\misc\\100Bot\\1v100_translated.mpeg");
if (capture == NULL) {
printf("capture is null");
} else {
cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, 0);
IplImage* oneFrame = cvQueryFrame(capture);
cvShowImage("win", oneFrame);
}
cvWaitKey(0);
cvReleaseImage(&img);
cvReleaseImage(&grayImg);
return 0;
}
开发者ID:HVisionSensing,项目名称:100Bot,代码行数:42,代码来源:OpenCVTest.cpp
示例11: connected_components
CvSeq* connected_components( IplImage* source, IplImage* result )
{
IplImage* binary_image = cvCreateImage( cvGetSize(source), 8, 1 );
cvConvertImage( source, binary_image );
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* contours = 0;
cvThreshold( binary_image, binary_image, 1, 255, CV_THRESH_BINARY );
cvFindContours( binary_image, storage, &contours, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
if (result)
{
cvZero( result );
for(CvSeq* contour = contours ; contour != 0; contour = contour->h_next )
{
CvScalar color = CV_RGB( rand()&255, rand()&255, rand()&255 );
/* replace CV_FILLED with 1 to see the outlines */
cvDrawContours( result, contour, color, color, -1, CV_FILLED, 8 );
}
}
return contours;
}
开发者ID:hahalaugh,项目名称:ComputerVision,代码行数:20,代码来源:road_signs.cpp
示例12: cvZero
void ShapeClassifier::UpdateContourImage() {
cvZero(filterImage);
// first, determine how many template contours we need to draw by counting the length of the sequence
int numContours = 0;
for (CvSeq *contour = templateContours; contour != NULL; contour = contour->h_next) {
numContours++;
}
if (numContours > 0) {
int gridSize = (int) ceil(sqrt((double)numContours));
int gridX = 0;
int gridY = 0;
int gridSampleW = FILTERIMAGE_WIDTH / gridSize;
int gridSampleH = FILTERIMAGE_HEIGHT / gridSize;
int contourNum = 0;
for (CvSeq *contour = templateContours; contour != NULL; contour = contour->h_next) {
cvSetImageROI(filterImage, cvRect(gridX*gridSampleW, gridY*gridSampleH, gridSampleW, gridSampleH));
CvRect bounds = cvBoundingRect(contour, 1);
int contourSize = max(bounds.width, bounds.height);
IplImage *contourImg = cvCreateImage(cvSize(contourSize, contourSize), filterImage->depth, filterImage->nChannels);
cvZero(contourImg);
cvDrawContours(contourImg, contour, colorSwatch[contourNum], CV_RGB(255,255,255), 0, 2, CV_AA, cvPoint(-bounds.x, -bounds.y));
cvResize(contourImg, filterImage);
cvReleaseImage(&contourImg);
cvResetImageROI(filterImage);
contourNum = (contourNum+1) % COLOR_SWATCH_SIZE;
gridX++;
if (gridX >= gridSize) {
gridX = 0;
gridY++;
}
}
}
IplToBitmap(filterImage, filterBitmap);
}
开发者ID:gotomypc,项目名称:eyepatch,代码行数:41,代码来源:ShapeClassifier.cpp
示例13: cvCreateImage
void Frame::fill()
{
IplImage *mor = cvCreateImage(cvGetSize(this->image), 8, 1);
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* contour = 0;
if(this->image->nChannels > 1) this->grayScale();
cvFindContours(this->image, storage, &contour, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
cvZero(mor);
for( ; contour != 0; contour = contour->h_next )
{
CvScalar color = CV_RGB( 255, 255, 255 );
cvDrawContours( mor, contour, color, color, 0, CV_FILLED, 8 );
}
cvConvertImage(mor, this->image, 0);
cvClearMemStorage(storage);
cvReleaseImage(&mor);
}
开发者ID:BietteMaxime,项目名称:vision-traffic-monitoring,代码行数:21,代码来源:Frame.cpp
示例14: on_trackbar
void on_trackbar(int) {
if( g_storage==NULL ) {
g_gray = cvCreateImage( cvGetSize(g_image), 8, 1 );
g_storage = cvCreateMemStorage(0);
} else {
cvClearMemStorage( g_storage );
}
CvSeq* contours = 0;
cvCvtColor( g_image, g_gray, CV_BGR2GRAY );
cvThreshold( g_gray, g_gray, g_thresh, 255, CV_THRESH_BINARY );
cvFindContours( g_gray, g_storage, &contours );
cvZero( g_gray );
if( contours )
cvDrawContours(
g_gray,
contours,
cvScalarAll(255),
cvScalarAll(255),
100
);
cvShowImage( "Contours", g_gray );
}
开发者ID:Halo9Pan,项目名称:tyro,代码行数:22,代码来源:ch8_ex8_2.cpp
示例15: cvFindContours
void BlobDetectionEngine::findBlobs(IplImage *grayImg, bool drawBlobs)
{
cvFindContours(grayImg, mem, &contours, sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
int i = 0;
for (ptr = contours; ptr != NULL; ptr = ptr->h_next) {
//Filter small contours
CvRect rect = cvBoundingRect(ptr);
if ( rect.height * rect.width < minAreaFilter ){
continue;
}
filtCont[i] = ptr;
//CvScalar color = CV_RGB( rand()&255, rand()&255, rand()&255 );
CvScalar color = CV_RGB( 255, 255, 255 );
cvDrawContours(visualImg, ptr, color, CV_RGB(0,0,0), 0, CV_FILLED, 8, cvPoint(0,0));
cvRectangle(visualImg, cvPoint(rect.x +3, rect.y +3), cvPoint(rect.x + rect.width, rect.y + rect.height), color, 1);
//sprintf(text, "B%d [%d,%d]", i, rect.x, rect.y);
sprintf(text, "Blob %d", i);
//cvPutText(visualImg, text, cvPoint(rect.x, rect.y), &font, color);
i++;
}
numOfFiltCont = i;
}
开发者ID:bairuiworld,项目名称:multiple-tracking-master,代码行数:23,代码来源:BlobDetectionEngine.cpp
示例16: FetchParams
void FindFeaturesPlugin::ProcessImage( ImagePlus *img ){
FetchParams();
IplImage *orig = img->orig;
if (!gray){
gray = cvCreateImage( cvGetSize(orig), IPL_DEPTH_8U, 1 );
cnt_mask = cvCreateImage(cvGetSize(orig), IPL_DEPTH_8U, 1);
eig = cvCreateImage( cvGetSize(orig), IPL_DEPTH_32F, 1 );
tempimg = cvCreateImage(cvGetSize(orig), IPL_DEPTH_32F, 1);
}
cvCvtColor(orig, gray, CV_BGR2GRAY);
CvPoint2D32f* feats = (CvPoint2D32f*)malloc(maxCount*sizeof(CvPoint2D32f));
for(int c=0; c<(int)img->contourArray.size(); c++){
int count = maxCount;
CvSeq *seq = img->contourArray[c];
cvZero(cnt_mask);
CvSeq *h_next = seq->h_next; seq->h_next = NULL;
cvDrawContours(cnt_mask, seq, CV_RGB(255,255,255), CV_RGB(0,0,0), 1, CV_FILLED, CV_AA, cvPoint(0,0));
seq->h_next = h_next;
cvGoodFeaturesToTrack( gray, eig, tempimg, feats, &count, quality, minDist, cnt_mask, blockSize, method, harrisK );
img->AddFeats(c, feats, count, clean);
}
free(feats);
}
开发者ID:conanhung,项目名称:examples,代码行数:24,代码来源:FindFeaturesPlugin.cpp
示例17: cvCreateMemStorage
void Image_OP::Draw_Contours(int threshold, IplImage * orig_img, IplImage* manipulated_img)
{
if( threshold > 0)
{
this->Reset_Manipulators();
this->my_pic_manipulators.contour_threshold = true;
bool already_exists = true;
// linked lists of memory blocks (for fast allocation or de-allocation)
CvMemStorage* mem_storage = cvCreateMemStorage(0);
// found contours are stored in a sequence
CvSeq* contours = 0;
// allocates mem for grey-scale image
IplImage* gray_img = cvCreateImage(cvSize(orig_img->width,orig_img->height),
IPL_DEPTH_8U, 1);
int found_contours =0;
if (manipulated_img == NULL)
{
already_exists = false;
manipulated_img = cvCreateImage(cvSize(orig_img->width,orig_img->height),
IPL_DEPTH_8U, 3);
}
cvNamedWindow("contours only");
// converts frame into grey-scale frame
cvCvtColor( orig_img, gray_img, CV_RGB2GRAY );
// extends threshold range
int g_thresh = threshold *5;
// defines a threshold for operations
// creates binary image (only 0 and 1 as pixel values)
// pixels will be set to 0, to the source value
// or to max value depending on threshold type
// here: CV_THRESH_BINARY => destination
// value = if source > threshold then MAX else 0
// Parameters => 1) source- and 2) destination image
// 3) threshold, 4) MAX value (255 in 8 bit grayscale) 5) threshold type
cvThreshold( gray_img, gray_img, g_thresh, 255, CV_THRESH_BINARY );
// findings contours; return value is number of found contours
// Parameters => 1) Image, that is used for computations
// 2) memory to store recorded contours, 3) pointer for stored contours 4) rest
// of parameters are optional
found_contours = cvFindContours(gray_img,mem_storage, &contours);
// sets all elements of an array to Null
cvZero( gray_img );
if( contours ){
// drawing contours: Parameters => 1) Image to draw on, 2) is sequence in which
// found contours were stored, 3) color of contour, 4) contours marked as a hole
// are drawn ins this color 5) depending on the number of max level contours of
// different levels are drawn; rest are optional arguments
cvDrawContours(gray_img,contours,cvScalarAll(255),cvScalarAll(255),100 );
}
this->my_manipulation_applied = threshold;
cvShowImage("contours only", gray_img);
// turn 1 channel image into 3 channel image (important for CvVideoWriter)
cvCvtColor( gray_img, manipulated_img, CV_GRAY2RGB );
// or: cvMerge(gray_img,gray_img,gray_img,NULL,manipulated_img);
cvReleaseImage(&gray_img);
cvReleaseMemStorage(&mem_storage);
if(already_exists == false)
cvReleaseImage(&manipulated_img);
}
}
开发者ID:surferran,项目名称:3Drobot,代码行数:79,代码来源:OpenCv_Video_METH.cpp
示例18: cvDrawContours
/**
- FUNCTION: FillBlob
- FUNCTIONALITY:
- Fills the blob with a specified colour
- PARAMETERS:
- imatge: where to paint
- color: colour to paint the blob
- RESULT:
- modifies input image and returns the seed point used to fill the blob
- RESTRICTIONS:
- AUTHOR: Ricard Borràs
- CREATION DATE: 25-05-2005.
- MODIFICATION: Date. Author. Description.
*/
void CBlob::FillBlob( IplImage *imatge, CvScalar color, int offsetX /*=0*/, int offsetY /*=0*/)
{
cvDrawContours( imatge, m_externalContour.GetContourPoints(), color, color,0, CV_FILLED, 8 );
}
开发者ID:ashokzg,项目名称:billiards,代码行数:18,代码来源:Blob.cpp
示例19: cvFindBlobsByCCClasters
void cvFindBlobsByCCClasters(IplImage* pFG, CvBlobSeq* pBlobs, CvMemStorage* storage)
{ /* Create contours: */
IplImage* pIB = NULL;
CvSeq* cnt = NULL;
CvSeq* cnt_list = cvCreateSeq(0,sizeof(CvSeq),sizeof(CvSeq*), storage );
CvSeq* clasters = NULL;
int claster_cur, claster_num;
pIB = cvCloneImage(pFG);
cvThreshold(pIB,pIB,128,255,CV_THRESH_BINARY);
cvFindContours(pIB,storage, &cnt, sizeof(CvContour), CV_RETR_EXTERNAL);
cvReleaseImage(&pIB);
/* Create cnt_list. */
/* Process each contour: */
for(; cnt; cnt=cnt->h_next)
{
cvSeqPush( cnt_list, &cnt);
}
claster_num = cvSeqPartition( cnt_list, storage, &clasters, CompareContour, NULL );
for(claster_cur=0; claster_cur<claster_num; ++claster_cur)
{
int cnt_cur;
CvBlob NewBlob;
double M00,X,Y,XX,YY; /* image moments */
CvMoments m;
CvRect rect_res = cvRect(-1,-1,-1,-1);
CvMat mat;
for(cnt_cur=0; cnt_cur<clasters->total; ++cnt_cur)
{
CvRect rect;
CvSeq* cnt;
int k = *(int*)cvGetSeqElem( clasters, cnt_cur );
if(k!=claster_cur) continue;
cnt = *(CvSeq**)cvGetSeqElem( cnt_list, cnt_cur );
rect = ((CvContour*)cnt)->rect;
if(rect_res.height<0)
{
rect_res = rect;
}
else
{ /* Unite rects: */
int x0,x1,y0,y1;
x0 = MIN(rect_res.x,rect.x);
y0 = MIN(rect_res.y,rect.y);
x1 = MAX(rect_res.x+rect_res.width,rect.x+rect.width);
y1 = MAX(rect_res.y+rect_res.height,rect.y+rect.height);
rect_res.x = x0;
rect_res.y = y0;
rect_res.width = x1-x0;
rect_res.height = y1-y0;
}
}
if(rect_res.height < 1 || rect_res.width < 1)
{
X = 0;
Y = 0;
XX = 0;
YY = 0;
}
else
{
cvMoments( cvGetSubRect(pFG,&mat,rect_res), &m, 0 );
M00 = cvGetSpatialMoment( &m, 0, 0 );
if(M00 <= 0 ) continue;
X = cvGetSpatialMoment( &m, 1, 0 )/M00;
Y = cvGetSpatialMoment( &m, 0, 1 )/M00;
XX = (cvGetSpatialMoment( &m, 2, 0 )/M00) - X*X;
YY = (cvGetSpatialMoment( &m, 0, 2 )/M00) - Y*Y;
}
NewBlob = cvBlob(rect_res.x+(float)X,rect_res.y+(float)Y,(float)(4*sqrt(XX)),(float)(4*sqrt(YY)));
pBlobs->AddBlob(&NewBlob);
} /* Next cluster. */
#if 0
{ // Debug info:
IplImage* pI = cvCreateImage(cvSize(pFG->width,pFG->height),IPL_DEPTH_8U,3);
cvZero(pI);
for(claster_cur=0; claster_cur<claster_num; ++claster_cur)
{
int cnt_cur;
CvScalar color = CV_RGB(rand()%256,rand()%256,rand()%256);
for(cnt_cur=0; cnt_cur<clasters->total; ++cnt_cur)
{
CvSeq* cnt;
int k = *(int*)cvGetSeqElem( clasters, cnt_cur );
if(k!=claster_cur) continue;
cnt = *(CvSeq**)cvGetSeqElem( cnt_list, cnt_cur );
cvDrawContours( pI, cnt, color, color, 0, 1, 8);
}
CvBlob* pB = pBlobs->GetBlob(claster_cur);
int x = cvRound(CV_BLOB_RX(pB)), y = cvRound(CV_BLOB_RY(pB));
//.........这里部分代码省略.........
开发者ID:AlexandreFreitas,项目名称:danfreve-blinkdetection,代码行数:101,代码来源:enteringblobdetection.cpp
示例20: Java_org_siprop_opencv_OpenCV_findContours
JNIEXPORT
jbooleanArray
JNICALL
Java_org_siprop_opencv_OpenCV_findContours(JNIEnv* env,
jobject thiz,
jint width,
jint height) {
IplImage *grayImage = cvCreateImage( cvGetSize(m_sourceImage), IPL_DEPTH_8U, 1 ); // グレースケール画像用IplImage
IplImage *binaryImage = cvCreateImage( cvGetSize(m_sourceImage), IPL_DEPTH_8U, 1 ); // 2値画像用IplImage
IplImage *contourImage = cvCreateImage( cvGetSize(m_sourceImage), IPL_DEPTH_8U, 3 ); // 輪郭画像用IplImage
// BGRからグレースケールに変換する
cvCvtColor( m_sourceImage, grayImage, CV_BGR2GRAY );
// グレースケールから2値に変換する
cvThreshold( grayImage, binaryImage, THRESHOLD, THRESHOLD_MAX_VALUE, CV_THRESH_BINARY );
// 輪郭抽出用のメモリを確保する
CvMemStorage* storage = cvCreateMemStorage( 0 ); // 抽出された輪郭を保存する領域
CvSeq* find_contour = 0; // 輪郭へのポインタ
// 2値画像中の輪郭を見つけ、その数を返す
int find_contour_num = cvFindContours(
binaryImage, // 入力画像(8ビットシングルチャンネル)
storage, // 抽出された輪郭を保存する領域
&find_contour, // 一番外側の輪郭へのポインタへのポインタ
sizeof( CvContour ), // シーケンスヘッダのサイズ
CV_RETR_LIST, // 抽出モード
CV_CHAIN_APPROX_NONE, // 推定手法
cvPoint( 0, 0 ) // オフセット
);
// 物体の輪郭を赤色で描画する
CvScalar red = CV_RGB( 255, 0, 0 );
cvDrawContours(
m_sourceImage, // 輪郭を描画する画像
find_contour, // 最初の輪郭へのポインタ
red, // 外側輪郭線の色
red, // 内側輪郭線(穴)の色
CONTOUR_MAX_LEVEL, // 描画される輪郭の最大レベル
LINE_THICKNESS, // 描画される輪郭線の太さ
LINE_TYPE, // 線の種類
cvPoint( 0, 0 ) // オフセット
);
int imageSize;
CvMat stub, *mat_image;
int channels, ipl_depth;
mat_image = cvGetMat( m_sourceImage, &stub );
channels = CV_MAT_CN( mat_image->type );
ipl_depth = cvCvToIplDepth(mat_image->type);
LOGV("Load loadImageBytes.");
WLNonFileByteStream* strm = new WLNonFileByteStream();
loadImageBytes(mat_image->data.ptr, mat_image->step, mat_image->width,
mat_image->height, ipl_depth, channels, strm);
imageSize = strm->GetSize();
jbooleanArray res_array = env->NewBooleanArray(imageSize);
LOGV("Load NewBooleanArray.");
if (res_array == 0) {
return 0;
}
env->SetBooleanArrayRegion(res_array, 0, imageSize, (jboolean*)strm->GetByte());
LOGV("Load SetBooleanArrayRegion.");
LOGV("Release sourceImage");
if (m_sourceImage) {
cvReleaseImage(&m_sourceImage);
m_sourceImage = 0;
}
LOGV("Release binaryImage");
cvReleaseImage( &binaryImage );
LOGV("Release grayImage");
cvReleaseImage( &grayImage );
LOGV("Release contourImage");
cvReleaseImage( &contourImage );
LOGV("Release storage");
cvReleaseMemStorage( &storage );
LOGV("Delete strm");
strm->Close();
SAFE_DELETE(strm);
return res_array;
}
开发者ID:273k,项目名称:OpenCV-Android,代码行数:86,代码来源:cvjni.cpp
注:本文中的cvDrawContours函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论