【发布时间】:2011-10-21 16:13:00
【问题描述】:
我有一个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;
第二次编辑 ==========================
这两个答案都有帮助,而且都是正确的。谢谢大家!问题已经解决了。 我使用了两个函数的双指针来将数据从函数 1 导出到函数 2 以及从函数 2 到主程序。我使用了一些帮助很大的临时变量。它不那么令人困惑。
【问题讨论】:
-
如果您在搜索中使用的关键字与您的问题中使用的关键字相似,那么您可能永远找不到答案...至少发布代码或其他内容...
-
未来的问题,请看how to markup your code