我有一个function1地方,我每次分配一个具有特定字节数的数组。
当我使用时printf,可以看到我的数据已加载到此阵列上。
function1 (other arguments, CvPoint2D32f* array1)
然后有一个function2我在其中调用function1并将array1数据分配给另一个变量(array2)。
function2(other stuff, CvPoint2D32f* array2)
使用时,printf我可以看到无法访问我的数据。程序打印0.000 ..
function2 由我的主程序调用,其中我将数据分配给第三个变量…
我搜索并且搜索,但是找不到错误所在。
传递指针还不够吗?
帮助,如果我不够具体,请问我:
function1(IplImage* grey, IplImage* image, CvPoint2D32f *array1){ int array_counter = cvFindContours(grey, storage_color, &colorcontoursizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0)); array1 = (CvPoint2D32f*)malloc(array_counter*sizeof(CvPoint2D32f)) if (array_counter == 0){ printf("Error allocating memory or Just a colour missing!!!\n\n\n"); free(Man); } cvReleaseMemStorage(&storage_color); // Releasing memory. free(Man); return array_counter; } int function2(IplImage* image, CvPoint2D32f *array2, other stuff){ ...other stuff... // Find the contours for the different colors. r_counter = function1(image1, image2, array2); return 0; }
编辑======================================
我在发布之前尝试过这样做,但这是我遇到的问题。
当我在array1中加载有关CvPoint2D32f的非类类型的数据的行上编译时出现错误。
这就是我在出现错误的以下行中所做的:
array1[cnt].x = (tpt1.x + tpt2.x)/2; array1[cnt].y = (tpt1.y + tpt2.y)/2;
第二次编辑=========================
两种答案都对并且是正确的。谢谢大家!问题已经解决了。我对两个函数都使用了双指针,以将数据从function1导出到function2以及从function2导出到主程序。我使用了一些临时变量,这很有帮助。它不那么混乱。