blackberry image processing [closed] - blackberry

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am very new to Blackberry development.
I am working with an Blackberry project.
In this project i want to change image effects and control.!
Image effects are sepia,sketch,grayscale,negative ,flip etc
and controls are brightness,contrast,hue etc
I have tried for flip image effect. following is code that i hav tried..
I got the output but it is overlapped with original image.
[image effect-flip output]
anybody can solve this issue??
Bitmap flip(Bitmap bitmap) {
int[] argb = new int[bitmap.getWidth() * bitmap.getHeight()];
bitmap.getARGB(argb, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
for (int i = 0; i < bitmap.getHeight(); i++) {
for (int j = 0; j < bitmap.getWidth(); j++) {
int swap = argb[i * bitmap.getWidth() + j];
argb[(bitmap.getHeight() - 1 - i) * bitmap.getWidth() + j] = swap;
}
}
//bitmap.setARGB(data, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
Graphics gr=new Graphics(bitmap);
gr.clear(0, 0, bitmap.getWidth(), bitmap.getHeight());
bitmap.setARGB(argb, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
return bitmap;
}
anybody can solve this issue??

You need to flip on a new argb (called argb_flip) as in:
public Bitmap flip(Bitmap bitmap) {
int[] argb = new int[bitmap.getWidth() * bitmap.getHeight()];
int[] argb_flip = new int[bitmap.getWidth() * bitmap.getHeight()];
bitmap.getARGB(argb, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
for (int i = 0; i < bitmap.getHeight(); i++) {
for (int j = 0; j < bitmap.getWidth(); j++) {
int swap = argb[i * bitmap.getWidth() + j];
argb_flip[(bitmap.getHeight() - 1 - i) * bitmap.getWidth() + j] = swap;
}
}
bitmap.setARGB(argb_flip, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
return bitmap;
}

Related

Cleaning up captcha image use OpenCV

How to clear the captcha picture of the interference line, when the interference line and the text of the same color
I try to use the following picture as a demo
demo picture
Use the following code processing
- (UIImage *)cleanLine:(UIImage *)image {
IplImage *src = [self convertToIplImage:image];
IplImage *gray = cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 1);
IplImage *dst = cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 1);
IplImage *binary = cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 1);
cvCvtColor(src, gray, CV_RGB2GRAY);
cvThreshold(gray, binary, 120, 255, CV_THRESH_OTSU);
findLines(gray, dst);
for (int row = 0; row < binary->height; row++)
for (int col = 0; col < binary->width; col++)
{
if (cvGet2D(dst, row, col).val[0] == 255)
{
int up = 0, down = 0;
int white = 0;
for (int i = row; i >= 0; i--)
{
if (cvGet2D(binary, i, col).val[0] == 0)
{
up++;
white = 0;
}
else white++;
if(white > 2) break;
}
white = 0;
for (int i = row; i < binary->height; i++)
{
if (cvGet2D(binary, i, col).val[0] == 0)
{
down++;
white = 0;
}
else white++;
if (white > 2) break;
}
if (up + down < 8)
{
for (int i = -up; i <= down; i++) cvSet2D(binary, row + i, col, cvScalar(255));
}
}
}
erase(binary);
cvErode(binary, binary, NULL, 1);
cvDilate(binary, binary, NULL, 1);
Mat Img = cvarrToMat(binary);
cvReleaseImage(&src);
cvReleaseImage(&gray);
cvReleaseImage(&dst);
cvReleaseImage(&binary);
return MatToUIImage(Img);
}
Find the line of interference code
void findLines(IplImage *raw, IplImage *dst) {
IplImage *src = cvCloneImage(raw);
IplImage *canny = cvCreateImage(cvGetSize(src), IPL_DEPTH_8U, 1);
cvCanny(src, canny, 20, 200, 3);
CvMemStorage *stor = cvCreateMemStorage(0);
CvSeq *lines = NULL;
lines = cvHoughLines2(canny, stor, CV_HOUGH_PROBABILISTIC, 1, CV_PI / 180, 80, 200, 30);
cvZero(dst);
CvPoint maxStart, maxEnd;
int maxDistance = 0;
for (int i = 0; i < lines->total; i++) {
CvPoint* line = (CvPoint*)cvGetSeqElem(lines, i);
if (abs(line[0].x - line[1].x) > maxDistance) {
maxDistance = abs(line[0].x - line[1].x);
maxStart = line[0];
maxEnd = line[1];
}
}
cvLine(dst, maxStart, maxEnd, cvScalar(255), 1);
cvReleaseImage(&src);
cvReleaseMemStorage(&stor);
}
Get the result picture result picture
I have a part of the captcha image here
captcha image
I used my code to process the captcha image, but it did not work
I do not know how to modify my code to make it clear the interference line
Anyone can guide me, thank you very much

Sizes of input arguments do not match in cvcalcopticalflowbm opencv 2.4.7

I want to calculate optical flow using cvcalcopticalflowBM function in opencv 2.4.7
When I complied the belowed code. The error message is "Sizes of input arguments do not macth() in cvcalcopticalflowbm
I do not understand why it is. Please help me. Thank you advance.
#define BS 5
IplImage *imgA = NULL, *imgB = NULL;
IplImage *grayA = NULL, *grayB = NULL;
IplImage *velx = NULL, *vely = NULL;
IplImage *result = NULL;
imgA = cvLoadImage("00.jpg", 1);
imgB = cvLoadImage("01.jpg", 1);
grayA = cvCreateImage(cvGetSize(imgA), IPL_DEPTH_8U, 1);
grayB = cvCreateImage(cvGetSize(imgA), IPL_DEPTH_8U, 1);
cvCvtColor(imgA, grayA, CV_BGR2GRAY);
cvCvtColor(imgB, grayB, CV_BGR2GRAY);
CvSize size = cvGetSize(imgA);
size.width /= BS;
size.height /= BS;
result = cvCreateImage(size, IPL_DEPTH_8U, 1);
for (int i=0; i<size.height; i++) {
for (int j=0; j<size.width; j++) {
cvSet(result, CV_RGB(255,255,255), NULL);
}
}
velx = cvCreateImage(size, IPL_DEPTH_32F, 1);
vely = cvCreateImage(size, IPL_DEPTH_32F, 1);
cvCalcOpticalFlowBM(grayB, grayA, cvSize(BS, BS), cvSize(1, 1), cvSize(1, 1), 0, velx, vely);
//
cvNamedWindow("HorFlowBM", CV_WINDOW_AUTOSIZE);
cvShowImage("HorFlowBM", velx);
cvNamedWindow("VerFlowBM", CV_WINDOW_AUTOSIZE);
cvShowImage("VerFlowBM", vely);
for (int i=0; i<size.height; i+=2) {
for (int j=0; j<size.width; j+=2) {
int dx = (int)cvGetReal2D(velx, i, j);
int dy = (int)cvGetReal2D(vely, i, j);
cvLine(result, cvPoint(j, i), cvPoint(j+dx, i+dy), CV_RGB(0,0,0), 1, 8, 0);
}
}
cvNamedWindow("OpticalFlow", CV_WINDOW_AUTOSIZE);
cvShowImage("OpticalFlow", result);
cvWaitKey(0);
Are you sure that the input images are getting load. Try to show them after loading them i.e. cvShowImage("input1", imgA);. Also, try to print the size of both the images to check that the size of both the images is same.
I recognized this error.
The size of velx and vely should be
CvSize velSize =
{
(grayA->width - BLOCK_SIZE + SHIFT_SIZE)/SHIFT_SIZE,
(grayA->height - BLOCK_SIZE + SHIFT_SIZE)/SHIFT_SIZE
};
It becomes correctly when complie the program

Mirroring the image in blackberry

Hi I want to convert normal image into mirror i.e flop effect in BLACKBERRY app.I have tried this code but unable too convert...Is there anyone to help me to do this...
If you have a different logic to do this please share..
public Bitmap changetoFlopEffect(Bitmap bitmap){
int[] argb = new int[bitmap.getWidth() * bitmap.getHeight()];
int[] newargb =new int[bitmap.getWidth() * bitmap.getHeight()];
int length=bitmap.getWidth();
bitmap.getARGB(argb, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
for(int i=0;i<=bitmap.getHeight();i++)
{
for(int j=bitmap.getWidth(),k=0;j>0;j--)
{
//newargb[k]=argb[j];
int swap=argb[j];
newargb[k]=swap;
k++;
}
}
bitmap.setARGB(newargb,0,bitmap.getWidth(),0,0,bitmap.getWidth(),bitmap.getHeight());
return bitmap;
}
Your corner conditions seem wrong and the pixels you swipe are from the first row only. Try this:
public Bitmap changetoFlopEffect(Bitmap bitmap){
int[] argb = new int[bitmap.getWidth() * bitmap.getHeight()];
int[] newargb =new int[bitmap.getWidth() * bitmap.getHeight()];
int length=bitmap.getWidth();
int newIndex = 0;
bitmap.getARGB(argb, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
for (int i = 0; i < bitmap.getHeight(); i++)
for (int j = bitmap.getWidth()-1; j >= 0 ; j--){
newargb[newIndex] = argb[i * bitmap.getWidth() + j];
newIndex++;
}
bitmap.setARGB(newargb,0,bitmap.getWidth(),0,0,bitmap.getWidth(),bitmap.getHeight());
return bitmap;
}

Feature tracking using Lucas Kanade

I am in the process of implementing Lucas-Kanade algorithm using OpenCv. Even though my intention is to track facial features, as a first cut i am getting all the good features using cvGoodFeatures api and using this points as the input, i am trying to track the points using Lucas-Kanade algorithm.
Now the scenario is if i start moving the objects captured by camera near to the edges of the frame(not out of the frame) what i observe is that LK algorithm starts giving me points that are either outside the frame or having negative values.
Please let me know whether i am doing a wrong implementation or is this behavior expected from LK tracking method. Also i am attaching my code at the end of this post for reference.
Regards,
Sujil C
IplImage *image = 0,
*grey = 0,
*prev_grey = 0,
*pyramid = 0,
*prev_pyramid = 0,
*swap_temp = 0,
*velx = 0,
*vely = 0;
const int MAX_COUNT = 20;
CvPoint2D32f* points[2] = {0,0}, *swap_points;
char* status = 0;
int lkcount = 0;
int detectGoodFeature = 0;
int flags = 0;
CvPoint pt;
CvSize currentFrameSize;
CvPoint2D32f* processLKFrame(IplImage* frame, int &pointCount)
{
int win_size = 15;
int level = 5;
int i, k;
// If frame size has changed, release all resources (they will be reallocated further on)
if ( (grey && ((currentFrameSize.width != cvGetSize(frame).width) || (currentFrameSize.height != cvGetSize(frame).height))))
{
// Release images
cvReleaseImage(&grey);
cvReleaseImage(&prev_grey);
cvReleaseImage(&pyramid);
cvReleaseImage(&prev_pyramid);
cvReleaseImage(&velx);
cvReleaseImage(&vely);
// Release buffers
cvFree(&(points[0]));
cvFree(&(points[1]));
cvFree(&status);
// Zerofiy grey so initialization will occur
grey = NULL;
}
// Initialize
if( !grey )
{
/* allocate all the buffers */
currentFrameSize = cvGetSize(frame);
grey = cvCreateImage( currentFrameSize, 8, 1 );
prev_grey = cvCreateImage( currentFrameSize, 8, 1 );
pyramid = cvCreateImage( currentFrameSize, 8, 1 );
prev_pyramid = cvCreateImage( currentFrameSize, 8, 1 );
velx = cvCreateImage(currentFrameSize, 32, 1);
vely = cvCreateImage(currentFrameSize, 32, 1);
points[0] = (CvPoint2D32f*)cvAlloc(MAX_COUNT*sizeof(points[0][0]));
points[1] = (CvPoint2D32f*)cvAlloc(MAX_COUNT*sizeof(points[0][0]));
status = (char*)cvAlloc(MAX_COUNT);
flags = 0;
}
printf("Current Frame Size : Width:%d Height:%d\n", currentFrameSize.width, currentFrameSize.height );
cvCopy( frame, grey, 0 );
if (detectGoodFeature) {
/* automatic initialization */
IplImage* eig = cvCreateImage( cvGetSize(grey), 32, 1 );
IplImage* temp = cvCreateImage( cvGetSize(grey), 32, 1 );
double quality = 0.01;
double min_distance = 10;
lkcount = MAX_COUNT;
cvGoodFeaturesToTrack( grey, eig, temp, points[1], &lkcount,
quality, min_distance, 0, 3, 0, 0.04 );
cvFindCornerSubPix( grey, points[1], lkcount,
cvSize(win_size,win_size), cvSize(-1,-1),
cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03));
cvReleaseImage( &eig );
cvReleaseImage( &temp );
}
else if( lkcount > 0 )
{
//For debugging points
printf("==============================================================================================================\n");
printf("Input Points:");
for (int i = 0; i < lkcount; i++) {
printf("(%f, %f)", points[0][i].x, points[0][i].y);
}
printf("\n");
// Calc movement of tracked points
cvCalcOpticalFlowPyrLK( prev_grey, grey, prev_pyramid, pyramid,
points[0], points[1], lkcount, cvSize(win_size,win_size), level, status, 0,
cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03), 0 );
//For debugging points
printf("Tracked Points:");
for (int i = 0; i < lkcount; i++) {
printf("(%f, %f),", points[1][i].x, points[1][i].y);
}
printf("\n");
printf("==============================================================================================================\n");
}
CV_SWAP( prev_grey, grey, swap_temp );
CV_SWAP( prev_pyramid, pyramid, swap_temp );
CV_SWAP( points[0], points[1], swap_points );
detectGoodFeature = 0;
pointCount = lkcount;
return points[0];
}

Blackberry: how to flip a Bitmap upside down?

How to flip a Bitmap upside down?
(I need this for loading an OpenGL texture in another program).
Here is my failed try:
stripe.png (courtesy of Pitr#OpenClipart):
Flip.java:
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
public class Flip extends UiApplication {
public static void main(String args[]) {
Flip app = new Flip();
app.enterEventDispatcher();
}
public Flip() {
pushScreen(new MyScreen());
}
}
class MyScreen extends MainScreen {
static final Bitmap STRIPE = flip(Bitmap.getBitmapResource("stripe.png"));
public MyScreen() {
setTitle("Flip the bitmap");
add(new BitmapField(STRIPE));
add(new ButtonField("Hello world"));
}
static Bitmap flip(Bitmap bitmap) {
int[] argb = new int[bitmap.getWidth() * bitmap.getHeight()];
bitmap.getARGB(argb, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
for (int i = 0; i < bitmap.getHeight(); i++) {
for (int j = 0; j < bitmap.getWidth(); j++) {
int swap = argb[i * bitmap.getWidth() + j];
argb[(bitmap.getHeight() - 1 - i) * bitmap.getWidth() + j] = swap;
}
}
bitmap.setARGB(argb, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
return bitmap;
}
}
Try using this bit of code:
for (int y = 0; y < bitmap.getHeight() / 2; y++) {
int upper_row = bitmap.getWidth() * y;
int lower_row = bitmap.getWidth() * (bitmap.getHeight() - 1 - y);
for (int x = 0; x < bitmap.getWidth(); x++) {
int temp = argb[upper_row + x];
argb[upper_row + x] = argb[lower_row + x];
argb[lower_row + x] = temp;
}
}
public Bitmap flip(Bitmap bitmap) {
int[] argb = new int[bitmap.getWidth() * bitmap.getHeight()];
int[] argb_flip = new int[bitmap.getWidth() * bitmap.getHeight()];
bitmap.getARGB(argb, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
for (int i = 0; i < bitmap.getHeight(); i++) {
for (int j = 0; j < bitmap.getWidth(); j++) {
int swap = argb[i * bitmap.getWidth() + j];
argb_flip[(bitmap.getHeight() - 1 - i) * bitmap.getWidth() + j] = swap;
}
}
bitmap.setARGB(argb_flip, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
return bitmap;
}
Try this, surely it will help you to flip the image by 180 degrees.

Resources