简体   繁体   English

人脸检测错误

[英]error on facedetection

I'am doing facedetection with the following java code as part of my project.iam getting a strange error 我正在使用以下java代码进行人脸检测作为我的项目的一部分。

BitmapFactory.Options BitmapFactoryOptionsbfo = new BitmapFactory.Options();

         /*BitMapFactory-Creates Bitmap objects from various sources, including 
          * files, streams, and byte-arrays. 
          */

         BitmapFactoryOptionsbfo.inPreferredConfig = Bitmap.Config.RGB_565; 

imageWidth = myBitmap.getWidth();

     imageHeight = myBitmap.getHeight();

    myFace = new FaceDetector.Face[numberOfFace];

    myFaceDetect = new FaceDetector(imageWidth, imageHeight, numberOfFace);

     numberOfFaceDetected = myFaceDetect.findFaces(myBitmap, myFace); 

     }

//i get error over there in R.drawable.pics      
myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pics, BitmapFactoryOptionsbfo);

I am supposed to give the name of the pic file in pics but it keeps giving me an error pics cannot be resolved or is not a field. 我应该在pics中给出pic文件的名称,但它一直给我一个错误的图片无法解析或不是字段。 So I set the name of the pic file as pic PS it's a jpg file in the drawable folder. 因此,我将图片文件的名称设置为pic PS,它是drawable文件夹中的jpg文件。 I also named the file within single quotes as 'pic' ---it gives me Invalid character constant error. 我还在单引号中将文件命名为“ pic” ---它给了我无效的字符常量错误。

I also named it within double quotes but it still doesn't work. 我也用双引号将其命名,但仍然无法正常工作。 I also named it 'pic.jpg' still doesn't work 我也将其命名为“ pic.jpg”仍然无效

Possibly there is another variable in your code named 'pics'. 您的代码中可能还有另一个名为“ pics”的变量。

Try saving it in a different folder, say MyPics. 尝试将其保存在其他文件夹中,例如MyPics。 And name the picture differently, say xyz1.jpg 然后用不同的名称命名图片,例如xyz1.jpg

In this case write the line as: 在这种情况下,将行写为:

myBitmap = BitmapFactory.decodeResource(getResources(), R.MyPics.xyz1, BitmapFactoryOptionsbfo);

Also, did you initialise 'myBitmap' as a bitmap image? 另外,您是否将“ myBitmap”初始化为位图图像? Meaning, did you include the line: 意思是,您是否包括以下行:

Bitmap myBitmap;

in your code, before performing the image read? 在您的代码中,在执行图像读取之前?

Just check with following line of code: 只需检查以下代码行:

 BitmapFactory.Options options = new BitmapFactory.Options();
 options.inPreferredConfig =  Bitmap.Config RGB_565;
 Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.icon,options);

Let me know whether it works or not? 让我知道它是否有效? Also check image names which appears after you type R.drawable. 还要检查键入R.drawable后出现的图像名称

EDIT: 编辑:

If still you are not able to access image from drawable, copy your image say pic.png to asset folder and access it using following code: 如果仍然无法从drawable访问图像,则将图像pic.png复制到资产文件夹,并使用以下代码进行访问:

Updated Code: 更新的代码:

try {
       InputStream bitmap=getAssets().open("icon.png");
       Bitmap bit=BitmapFactory.decodeStream(bitmap);
       img.setImageBitmap(bit);
     } catch (IOException e1) {
       // TODO Auto-generated catch block
       e1.printStackTrace();
     }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM