I am doing a CCPointFromString conversion but my coding crashing whenever I am trying to take input, Here is the code , what I am doing wrong?
CCPoint *temp = new CCPoint(oldLocationCon.x, oldLocationCon.y);
pointInsert->addObject(temp);
for(int i=0; i<pointInsert->count(); i++){
CCString point = (CCString*)pointInsert->objectAtIndex(i);
CCPoint savePoint= CCPointFromString(point->getCString());
}
CCArray * pointInsert = CCArray::create();
CCPoint * temp = new CCPoint(0, 0);
pointInsert->addObject(temp);
for(int i = 0; i < pointInsert->count(); i++){
CCString * point = static_cast<CCString*>(pointInsert->objectAtIndex(i));
CCPoint savePoint= CCPointFromString(point->getCString());
}
Related
I tried to display the text but it is displaying in wrong view. I want to display the Textview in reverse. I tried this code
String subMenuId = (String) key[position];
String subMenuName = subMenuTable.get(subMenuId);
for (int x = 0; x < subMenuName.length(); x++) {
int splitword = subMenuName.charAt(x);
char c = (char) splitword;
TextView product = new TextView(con);
product.setText(String.valueOf(c));
product.setRotation(-90);
holder.tv.setGravity(Gravity.CENTER_VERTICAL);
product.setTextSize(12);
holder.tv.setPadding(5,0,5,0);
product.setTextColor(Color.BLACK);
product.setTypeface(null, Typeface.BOLD);
holder.tv.addView(product);
}
Try the following
String reversedString = new StringBuilder("LIKE").reverse().toString()
Just reverse your loop
i.e.
for (int x = 0; x < subMenuName.length(); x++)
to
for (int x = subMenuName.length() -1; x >=0 ; x--)
Hope it helps
When you iterate from 0 ⇢ n first char get referred first and will be added to top. since you want it in reverse, iterate n ⇢ 0
I write a program which obtain value of color Asymmetric at lesion.
my program in visual studio Working correctly and I get color Asymmetric. But program in android (use Native) always return 0.
The problem is that points[j] always has same value therefor value of avg_i[i] with avg is equal.
my code:
Mat& srcMat = *(Mat*)src;
Mat& mask_tr = *(Mat*)Mask;
Mat gray;
cvtColor(srcMat, gray, CV_BGR2GRAY);
double summation=0, avg=0, NCD=0, mismatch=0;
double* avg_i = new double[p.size()];
double* ncd = new double[p.size()];
double* XOR_Cs_Cl = new double[p.size()];
int A_x=0, A_t=0;
vector<Vec3b> buf;
for(int i=0; i<p.size(); i++){
LineIterator it(gray, p5, p[i], 8);
vector<Point> points(it.count);
for(int j=0; j<it.count-1; j++)
{
buf.push_back( Vec3b(*it) );
points[j] = it.pos();
it=it++;
summation += int(gray.at<uchar>(points[j].y , points[j].x));
}
avg_i[i] = summation / (it.count-1);
summation = 0;
avg += avg_i[i];
}
avg = avg/p.size();
for(int i=0; i<p.size(); i++){
ncd[i] = avg_i[i] * (100/avg);
A_t += ncd[i];
XOR_Cs_Cl[i] = abs(100 - ncd[i]);
A_x += XOR_Cs_Cl[i];
}
mismatch = (double(A_x) / double(A_t))*100;
delete [] avg_i;
delete [] ncd;
return mismatch;
I am working to convert my CCScrollLayer.cpp code into more of a CCPicker code. In CCScrollLayer, I've defined a baselayer (CCColorLayer) to hold all of the menu objects. I also have a border that holds the ScrollLayer (using glScissor) called "overlay" that I want to be completely static.
In Objective C:
...
self.baseLayer = [CCLayerColor layerWithColor:(ccColor4B){150,150,150,0} width:s.width height:imgSize.height * numPages];
for (int i=0; i < [arrayPages count]; i++) {
CCNode* n = arrayPages[i];
n.position = ccp(s.width/2, s.height/2 + i * (imgSize.height + padding));
[baselayer addChild:n];
}
baseLayer.position = ccp(-s.width/2, -s.height/2 - s.height * currentPage);
[self addChild:baselayer];
...
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint n = [self convertTouchToNodeSpace:touch];
baselayer.position = ccp(touchStartedbaseLayerPosition.x, touchStartedbaseLayerPosition.y + n.y - touchStartedPoint.y);
}
In C++
...
overlay=new CCSprite();
overlay->initWithFile("overlay.png");
overlay->setPosition(ccp(300,300));
overlay->autorelease();
CCLayerColor* baselayer = new CCLayerColor();
baselayer->initWithColor(ccc4(255, 255, 255,255));
baselayer->setOpacity(255);
baselayer->setContentSize(CCSizeMake(s.width/10, (layers->count()*scrollWidth)));
baselayer->setPosition(s.width*.41,300);
baselayer->autorelease();
// Loop through the array and add the screens
unsigned int i;
for (i=0; i<layers->count(); i++)
{
CCLayer* l = static_cast<CCLayer*>(layers->objectAtIndex(i));
l->setAnchorPoint(ccp(0,0));
l->setPosition(ccp(s.width/40,(i*scrollWidth)));
baselayer->addChild(l);
}
this->addChild(baselayer,1);
this->addChild(overlay,1);
...
void CCScrollLayer::ccTouchMoved(CCTouch *touch, CCEvent *withEvent)
{
CCPoint touchPoint = touch->getLocation(); // Get the touch position
touchPoint = this->getParent()->convertToNodeSpace(touchPoint);
baselayer->setPosition(ccp(0,(-(currentScreen-1)*scrollWidth)+(touchPoint.y-startSwipe)));
}
I'm not sure what I'm doing wrong, but as soon as I try to start scrolling, I get a fatal error in the touchdispatcher
case CCTOUCHMOVED:
pHandler->getDelegate()->ccTouchMoved(pTouch, pEvent);
I'm guessing I'm missing something simple here. Can you point me in the write direction?
its may be a simple / stupid question, but I have a conversion problem in opencv (android).
my goal is to calculate the fundamentalMatrix out of corresponding matches from two consecutive images.
i programmed this so far (and working):
detector.detect(actImg, actKP);
detector.detect(prevImg, prevKP);
descExtractor.compute(prevImg, prevKP, descriptorPrev);
descExtractor.compute(actImg, actKP, descriptorAct);
descMatcher.match(descriptorPrev, descriptorAct, matches);
Features2d.drawMatches(prevImg, prevKP, actImg, actKP,matches, mRgba);
matches are of the type MatOfDMatch.
now i would calculate the fundamentalMatrix out of the points that matches against each other. therefor i must know which of the keypoints in the first image (prevKP) were found in the second image (actKP).
Mat fundamental_matrix = Calib3d.findFundamentalMat(nextPts, prevPts, Calib3d.FM_RANSAC,3, 0.99);
first question:
how can i extract / convert MatOfKeyPoints to MatOfPoint2f (that they can be passed to findFundamentalMatrix)
second question:
how to pass only the matched keypoints to the function findFundamentalMatrix.
is this a good way of doing it?
thanks a lot in advace!
EDIT
thanks a lot for your detailed response!
i wrote your code into two functions:
private MatOfPoint2f getMatOfPoint2fFromDMatchesTrain(MatOfDMatch matches2,
MatOfKeyPoint prevKP2) {
DMatch dm[] = matches2.toArray();
List<Point> lp1 = new ArrayList<Point>(dm.length);
KeyPoint tkp[] = prevKP2.toArray();
for (int i = 0; i < dm.length; i++) {
DMatch dmm = dm[i];
if (dmm.trainIdx < tkp.length)
lp1.add(tkp[dmm.trainIdx].pt);
}
return new MatOfPoint2f(lp1.toArray(new Point[0]));
}
private MatOfPoint2f getMatOfPoint2fFromDMatchesQuery(MatOfDMatch matches2,
MatOfKeyPoint actKP2) {
DMatch dm[] = matches2.toArray();
List<Point> lp2 = new ArrayList<Point>(dm.length);
KeyPoint qkp[] = actKP2.toArray();
for (int i = 0; i < dm.length; i++) {
DMatch dmm = dm[i];
if (dmm.queryIdx < qkp.length)
lp2.add(qkp[dmm.queryIdx].pt);
}
return new MatOfPoint2f(lp2.toArray(new Point[0]));
}
but when i am calling
prevPts = getMatOfPoint2fFromDMatchesTrain(matches, prevKP);
nextPts = getMatOfPoint2fFromDMatchesQuery(matches, actKP);
Mat fundamental_matrix = Calib3d.findFundamentalMat(
nextPts, prevPts, Calib3d.FM_RANSAC, 3, 0.99);
the problem is that i get the error -215.
the error:
error: (-215) npoints >= 0 && points2.checkVector(2) == npoints && points1.type() == points2.type() in function cv::Mat
cv::findFundamentalMat(...
i proved that prevPts and nextPts arend below 10 points (for ransac).
so i would guess that the error is that the points arend floating points. but i checked this with the debugger that these points are floating points.
your suggested codeline:
return new MatOfPoint2f(lp2.toArray(new Point[0]));
should convert the points to floating point or am i wrong?
thanks again
Unfortunately there is no better way (even in C++ API) than loop through all matches and copy values to new Mat (or vector).
In Java you can do it as follows:
DMatch dm[] = matches.toArray();
List<Point> lp1 = new ArrayList<Point>(dm.length);
List<Point> lp2 = new ArrayList<Point>(dm.length);
KeyPoint tkp[] = prevKP.toArray();
KeyPoint qkp[] = actKP.toArray();
for (int i = 0; i < dm.length; i++) {
DMatch dm = dm[i];
lp1.add(tkp[dm.trainIdx].pt);
lp2.add(qkp[dm.queryIdx].pt);
}
MatOfPoint2f pointsPrev = new MatOfPoint2f(lp1.toArray(new Point[0]));
MatOfPoint2f pointsAct = new MatOfPoint2f(lp2.toArray(new Point[0]));
I'm using the Kube application from Android API Samples for an application I'm working on.
The sample creates a model of the Rubik's Cube in OpenGL made out of 27 small cubes. Afterwards the cube is being scrambled in the animate() method by rotating random layers of the cube, after each rotation the layers are being set accordingly in a process I don't fully understand
// adjust mPermutation based on the completed layer rotation
int[] newPermutation = new int[27];
for (int i = 0; i < 27; i++) {
newPermutation[i] = mPermutation[mCurrentLayerPermutation[i]];
// newPermutation[i] = mCurrentLayerPermutation[mPermutation[i]];
}
mPermutation = newPermutation;
updateLayers();
The sample works fine but for some reason when I change the direction of the rotation to true, the cubes start overlapping each other, as if the layers weren't updated correctly.
Help would be appreciated :)
I solved the problem myself, so in case anyone is interested:
changing the direction to true makes the cube rotate in the other direction, which is like rotating three times in the regular direction so in order to save to cubes new location correctly I need to save the new location three times, as seen in the code below:
if (mAngleIncrement < 0) { // checks the turning direction
int[] newPermutation = new int[27];
for (int i = 0; i < 27; i++) {
newPermutation[i] = mPermutation[mCurrentLayerPermutation[i]];
}
mPermutation = newPermutation;
updateLayers();
}
else {
int[] newPermutation = new int[27];
for (int i = 0; i < 27; i++) {
newPermutation[i] = mPermutation[mCurrentLayerPermutation[i]];
}
mPermutation = newPermutation;
newPermutation = new int[27];
for (int i = 0; i < 27; i++) {
newPermutation[i] = mPermutation[mCurrentLayerPermutation[i]];
}
mPermutation = newPermutation;
newPermutation = new int[27];
for (int i = 0; i < 27; i++) {
newPermutation[i] = mPermutation[mCurrentLayerPermutation[i]];
}
mPermutation = newPermutation;
updateLayers();
}