The code works correctly, but the zbar plugin only reads the bar code on the horizontal and vertical axes.For this reason, I want to rotate the cross image at the end of the image output.So zbar will read the picture correctly.
But unfortunately I could not rotate the image correctly in the for loop. It rotates the image but does not do this for 180 degrees.I tried to write the code correctly, but I could not reach the end result.I think there's a problem with the warpaffine geometric tarnsformation function.
Any help will be apreciated to find the solution.
Here is example image outputs which is not properly rotated according to specified angle in for loop with explaination :
For loop(main code part) , which will be able to rotate image untill 120 degree of angle :
if ((zbar_scanner.barcode_string == "") || (zbar_scanner.barcode_string.length() <= 5)){
for (float tr = 0; tr <= 120; tr += 20){
cout << "ANGLE OF ROTATION" << tr << endl;
zbar_scanner.Image_Transform = Geometric_Transformation(zbar_scanner.cut_image_zbar1, tr);//call rotate function.It is available below.zbar_scanner.cut_image_zbar1 is the image that will be processed and rotated
zbar_scanner.scanner1.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
Image image1(zbar_scanner.Image_Transform.cols, zbar_scanner.Image_Transform.rows, "Y800", zbar_scanner.Image_Transform.data, zbar_scanner.Image_Transform.cols * zbar_scanner.Image_Transform.rows);
zbar_scanner.scanner1.scan(image1);
for (Image::SymbolIterator symbol1 = image1.symbol_begin();
symbol1 != image1.symbol_end();
++symbol1) {
// print out barcode string in each turn
cout << "DECODED " << symbol1->get_type_name() << " SYMBOL \"" << symbol1->get_data() << '"' << endl;
zbar_scanner.barcode_after_transform.append(symbol1->get_data());
}
if ((zbar_scanner.barcode_after_transform != "") || (zbar_scanner.barcode_after_transform.length() > 5)){
return zbar_scanner.barcode_after_transform;
break;//if barcode is read, break the for loop
}
image1.set_data(NULL, 0);
}
}
Here is the rotation function which is called above by
**> " zbar_scanner.Image_Transform =
Geometric_Transformation(zbar_scanner.cut_image_zbar1, tr);"
Mat Morphology::Geometric_Transformation(Mat& CutImage, float Transform){
src_center = Point2f(CutImage.cols /2 , CutImage.rows / 2); /// 2.0F /10.0f
rot_mat = getRotationMatrix2D(src_center, -Transform, 1);
rot_imagebox = RotatedRect(src_center, CutImage.size(), -Transform).boundingRect();
rot_mat.at<double>(0, 2) += rot_imagebox.width / 2.0 - src_center.x;//look for at command
rot_mat.at<double>(1, 2) += rot_imagebox.height / 2.0 - src_center.y;
if ((CutImage.cols > 0) && (CutImage.rows > 0)){
warpAffine(CutImage, dst, rot_mat, rot_imagebox.size()); //rotate image with given angle by for loop value
cvtColor(dst, dst, CV_RGB2GRAY);
imshow("Rotated Image", dst);
}
return dst; //return otput image for each rotation
}