error: invalid lvalue in assignment

M

mundacho

Hello,

I'm getting this error:

../templates.hpp: In function 'Img crop(const Img&, const
cvmlcpp::iPoint2D&, const cvmlcpp::iPoint2D&) [with Img =
ili::BWImg]':
RectangleImageComparator.cc:85: instantiated from here
../templates.hpp:61: error: invalid lvalue in assignment

What's weird is that exactly the same template works with another
image type, as in the file where I instantiate it I have:

-------- begin extract RectangleImageComparator.cc -------
84 IntImg rectImg = crop<IntImg>(tempImage, corners[0],
corners[2]); // this function instantiates correctly
85 BWImg rectBWI = crop<BWImg>(bwImage, corners[0],
corners[2]); // if I eliminate this line (and all that uses the
result) all the code works
-------- end extract RectangleImageComparator.cc -------

The images are template classes defined like this:


typedef cvmlcpp::Matrix<bool , 2u> BWImg;
typedef cvmlcpp::Matrix<int_t, 2u> IntImg;

So, why would the instantiation work with the int version and not with
the boolean?? What does it mean the "error: invalid lvalue in
assignment", why does it appear only in the instantiation on the
boolean img??

Thanks for your help,

eD


-------- begin extract templates.hpp -------

29 template <class Img>
30 Img crop(const Img &img, const cvmlcpp::iPoint2D &ulc,
31 const cvmlcpp::iPoint2D &brc)
32 {
33 typedef typename Img::value_type T;
34
35
36 // check for valid arguments
37 // the image itself will take care of the out of bound
exception
38
39 /// \todo TODO put this function in the library
40 unsigned newHeight = ((brc[0] - ulc[0]) > 0) ? (brc[0] - ulc
[0]) : 0;
41 unsigned newWidth = ((brc[1] - ulc[1]) > 0) ? (brc[0] - ulc
[0]) : 0;
42
43 if (newHeight == 0)
44 {
45 std::invalid_argument myException("Height");
46 throw myException;
47 }
48 else if (newWidth == 0)
49 {
50 std::invalid_argument myException("Width");
51 throw myException;
52 }
53
54 Img myImage = ili::init<Img>(newHeight, newWidth);
55
56 // now we do the copying
57 for (unsigned i = 0; i < newHeight; i++)
58 {
59 for (unsigned j = 0; j < newWidth; j++)
60 {
61 myImage[j] = img[ulc[0] + i][ulc[1] + j]; // this
would be the line
62 }
63 }
64
65 return myImage;
66 }
 
K

Kai-Uwe Bux

Hello,

I'm getting this error:

./templates.hpp: In function 'Img crop(const Img&, const
cvmlcpp::iPoint2D&, const cvmlcpp::iPoint2D&) [with Img =
ili::BWImg]':
RectangleImageComparator.cc:85: instantiated from here
./templates.hpp:61: error: invalid lvalue in assignment

What's weird is that exactly the same template works with another
image type, as in the file where I instantiate it I have:

-------- begin extract RectangleImageComparator.cc -------
84 IntImg rectImg = crop<IntImg>(tempImage, corners[0],
corners[2]); // this function instantiates correctly
85 BWImg rectBWI = crop<BWImg>(bwImage, corners[0],
corners[2]); // if I eliminate this line (and all that uses the
result) all the code works
-------- end extract RectangleImageComparator.cc -------

The images are template classes defined like this:


typedef cvmlcpp::Matrix<bool , 2u> BWImg;
typedef cvmlcpp::Matrix<int_t, 2u> IntImg;

So, why would the instantiation work with the int version and not with
the boolean??
[snip]

I am going to take a wild guess here since you failed to post enough code to
reproduce the problem: Could it be that your cvmlcpp::Matrix<T,N> template
uses a vector<T> internally? In that case, beware that vector<bool> is a
specialization that obeys peculiar rules. In particular, operator[] and the
like to not return references but proxies.


Best

Kai-Uwe Bux
 
M

mundacho

I'm getting this error:
./templates.hpp: In function 'Img crop(const Img&, const
cvmlcpp::iPoint2D&, const cvmlcpp::iPoint2D&) [with Img =
ili::BWImg]':
RectangleImageComparator.cc:85:   instantiated from here
./templates.hpp:61: error: invalid lvalue in assignment
What's weird is that exactly the same template works with another
image type, as in the file where I instantiate it I have:
-------- begin extract RectangleImageComparator.cc -------
 84             IntImg rectImg = crop<IntImg>(tempImage, corners[0],
corners[2]); // this function instantiates correctly
 85             BWImg  rectBWI = crop<BWImg>(bwImage, corners[0],
corners[2]); // if I eliminate this line (and all that uses the
result) all the code works
-------- end extract RectangleImageComparator.cc -------
The images are template classes defined like this:
typedef cvmlcpp::Matrix<bool , 2u> BWImg;
typedef cvmlcpp::Matrix<int_t, 2u> IntImg;
So, why would the instantiation work with the int version and not with
the boolean??

[snip]

I am going to take a wild guess here since you failed to post enough code to
reproduce the problem: Could it be that your cvmlcpp::Matrix<T,N> template
uses a vector<T> internally? In that case, beware that vector<bool> is a
specialization that obeys peculiar rules. In particular, operator[] and the
like to not return references but proxies.

Best

Kai-Uwe Bux

Wow!!! I've just checked and in fact, cvmlcpp uses vector<bool> for
the matrix implementation!!!
Thanks a lot!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top