Commit 570041fe authored by Leonid Beynenson's avatar Leonid Beynenson

Fixed bug in modules/java/src/cpp/Mat.cpp

Removed some debugging insertions.
Added test for face detector.
Allowed tests to write on sdcard.
parent 75bcb1bc
...@@ -14,5 +14,5 @@ ...@@ -14,5 +14,5 @@
<uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" /> <uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
</manifest> </manifest>
\ No newline at end of file
...@@ -4,18 +4,18 @@ import java.util.ArrayList; ...@@ -4,18 +4,18 @@ import java.util.ArrayList;
import org.opencv.Mat; import org.opencv.Mat;
import org.opencv.objdetect; import org.opencv.objdetect;
import org.opencv.imgproc;
import org.opencv.highgui; import org.opencv.highgui;
import org.opencv.core; import org.opencv.core;
import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestCase;
import org.opencv.test.OpenCVTestRunner; import org.opencv.test.OpenCVTestRunner;
import org.opencv.Rect; import org.opencv.Rect;
import org.opencv.Size; import org.opencv.Size;
import org.opencv.Scalar;
public class objdetectTest extends OpenCVTestCase { public class objdetectTest extends OpenCVTestCase {
public void testCascadeClassifierFaceDetector() { public void testCascadeClassifierFaceDetector() {
//objdetect.CascadeClassifier cc=new objdetect.CascadeClassifier("/mnt/sdcard/lbpcascade_frontalface.xml"); objdetect.CascadeClassifier cc=new objdetect.CascadeClassifier("/mnt/sdcard/lbpcascade_frontalface.xml");
objdetect.CascadeClassifier cc=new objdetect.CascadeClassifier("/mnt/sdcard/haarcascade_frontalface_alt2.xml"); ///objdetect.CascadeClassifier cc=new objdetect.CascadeClassifier("/mnt/sdcard/haarcascade_frontalface_alt2.xml");
ArrayList<Rect> faces=new ArrayList<Rect>(); ArrayList<Rect> faces=new ArrayList<Rect>();
...@@ -24,6 +24,16 @@ public class objdetectTest extends OpenCVTestCase { ...@@ -24,6 +24,16 @@ public class objdetectTest extends OpenCVTestCase {
cc.detectMultiScale(shot002, faces, 1.1, 2, 2 /*TODO: CV_HAAR_SCALE_IMAGE*/, new Size(10,10)); cc.detectMultiScale(shot002, faces, 1.1, 2, 2 /*TODO: CV_HAAR_SCALE_IMAGE*/, new Size(10,10));
OpenCVTestRunner.Log("faces.size="+faces.size()); OpenCVTestRunner.Log("faces.size="+faces.size());
Scalar color=new Scalar(0,255,0);
for(int i=0; i < faces.size(); i++) {
OpenCVTestRunner.Log("face["+i+"]="+faces.get(i).toString());
core.rectangle(shot002, faces.get(i).tl(), faces.get(i).br(), color);
}
OpenCVTestRunner.Log("before writing image");
boolean reswrite=highgui.imwrite("/mnt/sdcard/lbpcascade_frontalface_res.jpg", shot002);
OpenCVTestRunner.Log("after writing image, res="+reswrite);
} }
......
...@@ -231,6 +231,7 @@ template<typename T> int mat_get(cv::Mat* m, int row, int col, int count, char* ...@@ -231,6 +231,7 @@ template<typename T> int mat_get(cv::Mat* m, int row, int col, int count, char*
if(! m) return 0; if(! m) return 0;
if(! buff) return 0; if(! buff) return 0;
count *= sizeof(T);//This change is required, checked TODO: recheck for non-continious case
int rest = ((m->rows - row) * m->cols - col) * m->channels() * sizeof(T); int rest = ((m->rows - row) * m->cols - col) * m->channels() * sizeof(T);
if(count>rest) count = rest; if(count>rest) count = rest;
int res = count; int res = count;
...@@ -243,7 +244,7 @@ template<typename T> int mat_get(cv::Mat* m, int row, int col, int count, char* ...@@ -243,7 +244,7 @@ template<typename T> int mat_get(cv::Mat* m, int row, int col, int count, char*
int num = (m->cols - col - 1) * m->channels() * sizeof(T); // 1st partial row int num = (m->cols - col - 1) * m->channels() * sizeof(T); // 1st partial row
if(count<num) num = count; if(count<num) num = count;
uchar* data = m->ptr(row++, col); uchar* data = m->ptr(row++, col);
while(count>0){ while(count>0){//TODO: recheck this cycle for the case col!=0
memcpy(buff, data, num); memcpy(buff, data, num);
count -= num; count -= num;
buff += num; buff += num;
......
...@@ -91,7 +91,6 @@ void Mat_to_vector_uchar(cv::Mat& mat, std::vector<uchar>& v_uchar) ...@@ -91,7 +91,6 @@ void Mat_to_vector_uchar(cv::Mat& mat, std::vector<uchar>& v_uchar)
void Mat_to_vector_Rect(Mat& mat, vector<Rect>& v_rect) void Mat_to_vector_Rect(Mat& mat, vector<Rect>& v_rect)
{ {
LOGD("Mat_to_vector_Rect start, mat.cols=%d", mat.cols);
v_rect.clear(); v_rect.clear();
if(mat.type()!= CV_32SC4 || mat.rows!=1) { if(mat.type()!= CV_32SC4 || mat.rows!=1) {
...@@ -103,17 +102,14 @@ void Mat_to_vector_Rect(Mat& mat, vector<Rect>& v_rect) ...@@ -103,17 +102,14 @@ void Mat_to_vector_Rect(Mat& mat, vector<Rect>& v_rect)
Vec<int, 4> v=mat.at< Vec<int, 4> >(0, i); Vec<int, 4> v=mat.at< Vec<int, 4> >(0, i);
v_rect.push_back( Rect(v[0], v[1], v[2], v[3]) ); v_rect.push_back( Rect(v[0], v[1], v[2], v[3]) );
} }
LOGD("Mat_to_vector_Rect end, vec.size=%d", (int)v_rect.size());
} }
void vector_Rect_to_Mat(vector<Rect>& v_rect, Mat& mat) void vector_Rect_to_Mat(vector<Rect>& v_rect, Mat& mat)
{ {
LOGD("vector_Rect_to_Mat start, vec.size=%d", (int)v_rect.size());
mat.create(1, v_rect.size(), CV_32SC4); mat.create(1, v_rect.size(), CV_32SC4);
for(size_t i=0; i<v_rect.size(); i++) { for(size_t i=0; i<v_rect.size(); i++) {
mat.at< Vec<int, 4> >(0, i) = Vec<int, 4>(v_rect[i].x, v_rect[i].y, v_rect[i].width, v_rect[i].height); mat.at< Vec<int, 4> >(0, i) = Vec<int, 4>(v_rect[i].x, v_rect[i].y, v_rect[i].width, v_rect[i].height);
} }
LOGD("vector_Rect_to_Mat end, mat.cols=%d", mat.cols);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment