Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android中从数组打印坐标_Android_Image Processing_Pixels - Fatal编程技术网

在Android中从数组打印坐标

在Android中从数组打印坐标,android,image-processing,pixels,Android,Image Processing,Pixels,我正在开发一个分析心电图图的图像处理应用程序。为此,我需要检测图形的某些峰值 如何在用户界面中打印“坐标”、“xcoor”和“ycoor”?我试着为它干杯,但没用。我尝试了textView,但应用程序强制关闭 package com.thesis.results; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.g

我正在开发一个分析心电图图的图像处理应用程序。为此,我需要检测图形的某些峰值

如何在用户界面中打印“坐标”、“xcoor”和“ycoor”?我试着为它干杯,但没用。我尝试了textView,但应用程序强制关闭

package com.thesis.results;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.util.ArrayList;
import android.widget.Toast;


import com.example.edgedetection.R;

public class MainActivity extends Activity {

    // initialize variables
    static int i = 0;
    static int bl_ = 0; // number of black; pixels in the image
    static int op_ = 0;
    static int Al = 0;
    static int Re = 0;
    static int Gr = 0;
    static int Bl = 0;
    static int Alp = 0;
    static int Red = 0;
    static int Gre = 0;
    static int Blu = 0;
    static int stop = 0;
    static int stopx = 0;
    static int stopy = 1000;
    static int xcoor[];
    static int ycoor[];
    static int width;
    static int height;
    static int RRdistance;
    static double voltage;
    static int peakcoordinates;

    ImageView imageSource, imageAfter;
    Bitmap bitmap_Source;
    ProgressBar progressBar;
    Button process;
    TextView counter;
    TextView coordinates;
    private Handler handler;
    Bitmap afterProcess;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        process = (Button) findViewById(R.id.btn_process);
        imageSource = (ImageView) findViewById(R.id.imageSource);
        imageAfter = (ImageView) findViewById(R.id.imageAfter);
        progressBar = (ProgressBar) findViewById(R.id.progressBar);
        counter = (TextView) findViewById(R.id.counter);
        coordinates = (TextView) findViewById(R.id.coordinates);

        process.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                bitmap_Source = BitmapFactory.decodeResource(getResources(),
                        R.drawable.test_ideal_graph);
                handler = new Handler();
                StratBackgroundProcess();
            }
        });

    }

    private void StratBackgroundProcess() {

        Runnable runnable = new Runnable() {

            public void run() {
                afterProcess = processingBitmap(bitmap_Source, 0, 0, 0);

                handler.post(new Runnable() {

                    public void run() {
                        progressBar.setVisibility(View.GONE);
                        imageAfter.setImageBitmap(afterProcess);

                        calculatevoltage();
                        //  calculateRRdistance();
                        counter.setText("" + bl_ + "@ (" + stopx + "," + stopy
                                + " " + "and" + 
                                ")" + " {" + width + "," + height + " } = "
                                        + voltage + "mV" + " " + "R-R distance:" + " "
                                        + RRdistance);

                        coordinates.setText(" " + xcoor + "," + ycoor + " " );
                    }

                    private void calculatevoltage() {
                        // TODO Auto-generated method stub
                        voltage = ((0.1 * height) * (height - stopy)) / height;
                        // 1.5 mV is the total voltage of the graph, 1 box =
                        // 0.1mV
                    }

                    //private void calculateRRdistance() {
                    // TODO Auto-generated method stub
                    //     RRdistance = stopx1 - stopx;
                    // 1.5 mV is the total voltage of the graph, 1 box =
                    // 0.1mV

                    //   }

                });
            }
        };
        new Thread(runnable).start();
    }

    public static Bitmap processingBitmap(Bitmap src, double red, double green,
            double blue) {
        // image size
        width = src.getWidth();
        height = src.getHeight();
        // create output bitmap
        Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
        // color information
        int A, R, G, B;
        int pixel;
        int flag = 0;

        //array
        int[] trial = new int[width];
        // scan through all pixels

        for (int x = 0; x < width; ++x) {

            flag = 0;

            for (int y = 0; y < height; ++y) {
                // get pixel color
                pixel = src.getPixel(x, y);
                // apply filtering on each channel R, G, B
                Al = Color.alpha(pixel);
                Re = (int) (Color.red(pixel));
                Gr = (int) (Color.green(pixel));
                Bl = (int) (Color.blue(pixel));
                // set new color pixel to output bitmap

                if ((Re == 0) && (Gr == 0) && (Bl == 0) && (flag == 0)) {
                    bmOut.setPixel(x, y, Color.argb(255, 0, 0, 0));
                    flag = 1;
                    trial[x] = y;

                } else
                    bmOut.setPixel(x, y, Color.argb(255, 255, 255, 255));

            }
        }

        //detect all possible peaks

        for (int x = 1; x < width; x++) {
            if (trial[x] < trial[x - 1] && trial[x] < trial[x + 1]) {
                peakcoordinates = src.getPixel(x, trial[x]); //get pixels, how to display? (textview, toast?)
                //Toast.makeText(getApplicationContext(), "hi", Toast.LENGTH_LONG).show();
            }

            //detect all R peaks
            for (int y = 1; y > (trial[1]-50); y++ ){

                xcoor[i] = x;
                ycoor[i] = y;
            }
            return bmOut;
        }
        return bmOut;
    }
}
package com.dispose.results;
导入android.app.Activity;
导入android.graphics.Bitmap;
导入android.graphics.BitmapFactory;
导入android.graphics.Color;
导入android.os.Bundle;
导入android.os.Handler;
导入android.view.view;
导入android.widget.Button;
导入android.widget.ImageView;
导入android.widget.ProgressBar;
导入android.widget.TextView;
导入java.util.ArrayList;
导入android.widget.Toast;
导入com.example.edgedetection.R;
公共类MainActivity扩展了活动{
//初始化变量
静态int i=0;
静态int bl=0;//图像中的黑色像素数
静态int op_u2;=0;
静态int Al=0;
静态int Re=0;
静态int Gr=0;
静态int Bl=0;
静态积分Alp=0;
静态int Red=0;
静态int Gre=0;
静态int Blu=0;
静态int stop=0;
静态int-stopx=0;
静态int stopy=1000;
静态int xcoor[];
静态int ycoor[];
静态整数宽度;
静态内高度;
静态距离;
静态双电压;
静态内峰值坐标;
ImageView imageSource,imageAfter;
位图源;
ProgressBar ProgressBar;
按钮过程;
文本视图计数器;
文本视图坐标;
私人经办人;
位图后处理;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
进程=(按钮)findViewById(R.id.btn_进程);
imageSource=(ImageView)findViewById(R.id.imageSource);
imageAfter=(ImageView)findViewById(R.id.imageAfter);
progressBar=(progressBar)findViewById(R.id.progressBar);
计数器=(TextView)findViewById(R.id.counter);
坐标=(TextView)findViewById(R.id.coordinates);
process.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
//TODO自动生成的方法存根
位图_Source=BitmapFactory.decodeResource(getResources(),
R.可绘制、测试(理想图);
handler=新的handler();
StratBackgroundProcess();
}
});
}
私人背景流程(){
Runnable Runnable=新的Runnable(){
公开募捐{
后处理=处理位图(位图\源,0,0,0);
handler.post(新的Runnable(){
公开募捐{
progressBar.setVisibility(View.GONE);
设置图像位图(后处理);
calculatevoltage();
//计算距离();
计数器.setText(“+bl_u+”@(“+stopx+”,“+stopy
+“+”和“+
“”“+”{“+宽度+”,“+高度+”}=”
+电压+“mV”+“+”R-R距离:“+”
+距离);
坐标.setText(“+xcoor+”,“+ycoor+”);
}
私有void calculatage(){
//TODO自动生成的方法存根
电压=((0.1*高度)*(高度-停止))/高度;
//1.5 mV是图中的总电压,1框=
//0.1mV
}
//私有void calculaterDistance(){
//TODO自动生成的方法存根
//RRdistance=stopx1-stopx;
//1.5 mV是图中的总电压,1框=
//0.1mV
//   }
});
}
};
新线程(runnable.start();
}
公共静态位图处理位图(位图src、双红、双绿、,
双蓝){
//图像大小
宽度=src.getWidth();
height=src.getHeight();
//创建输出位图
Bitmap bmOut=Bitmap.createBitmap(宽度、高度,src.getConfig());
//颜色信息
int A,R,G,B;
整数像素;
int标志=0;
//排列
int[]试用=新int[宽度];
//扫描所有像素
对于(int x=0;x@Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        process = (Button) findViewById(R.id.btn_process);
        imageSource = (ImageView) findViewById(R.id.imageSource);
        imageAfter = (ImageView) findViewById(R.id.imageAfter);
        progressBar = (ProgressBar) findViewById(R.id.progressBar);
        counter = (TextView) findViewById(R.id.counter);
        coordinates = (TextView) findViewById(R.id.coordinates);

        process.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {
                        // TODO Auto-generated method stub
                        bitmap_Source = BitmapFactory.decodeResource(getResources(),
                                        R.drawable.test_ideal_graph);
                        handler = new Handler();
                        new BackgroundTask().execute();
                }
        });

}

private class BackgroundTask extends AsyncTask<String, Long, String> {

    @Override
    protected String doInBackground(String... s) {
        afterProcess = processingBitmap(bitmap_Source, 0, 0, 0);
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        progressBar.setVisibility(View.GONE);
        imageAfter.setImageBitmap(afterProcess);

        calculatevoltage();
        //  calculateRRdistance();
        counter.setText("...");
        coordinates.setText(" " + xcoor + "," + ycoor + " " );
    }
}