开发者

C++ - pointer value

In the Learning OpenCV book:

.
.
CvCapture *capture = cvCreateFileCapture(argv[1]);
IplImage* frame;
while(1)
{
frame = cvQueryFrame(capture);
.
.
}

Here, we can see that *frame is a pointer. But, when we write the following frame = cvQueryFrame(capture);,开发者_StackOverflow we are not assigning an address to the pointer. What exactly will the values be that frame will hold in this case?

Thanks.


frame is pointer to an object of type IplImage. Presumably, the cvQueryFrame() function allocates an IplImage object and returns the address of this object. The statement

frame = cvQueryFrame(capture);

assigns the value of this returned pointer to frame. If indeed the function is allocating a new object you'll probably be required to free this memory later by calling operator delete or some function like

void cvDestroyFrame( IplImage * );

Also the statement you make at the end of your question ("*frame is a pointer") is not accurate - frame is a pointer; *frame means you're de-referencing the pointer which makes its type IplImage.


But, when we write the following frame = cvQueryFrame(capture);, we are not assigning an address to the pointer.

Actually we are assigning address to the pointer. cvQueryFrame returns pointer value (address).


Actually, *frame is a dereferenced pointer that will give the object pointed to by the pointer frame. In this case, the function cvQueryFrame() is returning a pointer that is being assigned to frame.


Since you didn't provide a prototype of cvQueryFrame (I'm not familiar with this library), I'm going to assume its return type is of IplImage*. What this method is probably doing is allocating some memory within itself and then returning the address from the allocation. So you are in reality, setting to an address.


The function cvQueryFrame returns a pointer to IplImage, that means your code does assign an address to the pointer. Here is the signature of the function:

IplImage* cvQueryFrame( CvCapture* capture );

Read about it in the manual:

  • HighGUI Reference Manual
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜