EXC_Bad_Access while analyzing sampleBuffer in OpenCV - c++

I am trying to to do a real-time camera processing with OpenCV.
In the didOutputSampleBuffer-Method of AVCaptureVideoDataOutputSampleBufferDelegate I am creating a matrix out of a sampleBuffer (which works without any problems). But when performing certain methods, such as cv::GaussianBlur, the app crashes because of "exc_bad_access code=1, address = 0x10......". Do you know why?
cv::Mat matrix(bufferHeight, bufferWidth, CV_8UC4, baseAddress);
cv::GaussianBlur(matrix, matrix, cvSize(5,5), 0); // Crahes here
__ Edit:
Base Address is calculated as below (this is done in Swift in didOutputSampleBuffer-Method, before passing these variables to objective-c++)
var pixelBuffer: CVImageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)!
CVPixelBufferLockBaseAddress(pixelBuffer, CVPixelBufferLockFlags(rawValue: 0))
var baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer)
____ Edit2:
Value of baseAddress:
0x0000000107790000
Value of pixelBuffer:
<CVPixelBuffer 0x17413aae0 width=1920 height=1080 pixelFormat=420v iosurface=0x1700039e0 planes=2>
<Plane 0 width=1920 height=1080 bytesPerRow=1920>
<Plane 1 width=960 height=540 bytesPerRow=1920>
<attributes=<CFBasicHash 0x17426e640 [0x1b8d18bb8]>{type = immutable dict, count = 5,
entries =>
0 : <CFString 0x1b300de28 [0x1b8d18bb8]>{contents = "PixelFormatDescription"} = <CFBasicHash 0x17426a080 [0x1b8d18bb8]>{type = immutable dict, count = 10,
entries =>
0 : <CFString 0x1b300e088 [0x1b8d18bb8]>{contents = "Planes"} = (
{
BitsPerBlock = 8;
BlackBlock = <10>;
FillExtendedPixelsCallback = <00000000 00000000 b840aa95 01000000 00000000 00000000>;
},
{
BitsPerBlock = 16;
BlackBlock = <8080>;
FillExtendedPixelsCallback = <00000000 00000000 443faa95 01000000 00000000 00000000>;
HorizontalSubsampling = 2;
VerticalSubsampling = 2;
}
)
2 : <CFString 0x1b300dd68 [0x1b8d18bb8]>{contents = "IOSurfaceOpenGLESFBOCompatibility"} = <CFBoolean 0x1b8d19110 [0x1b8d18bb8]>{value = true}
3 : <CFString 0x1b300e228 [0x1b8d18bb8]>{contents = "ContainsYCbCr"} = <CFBoolean 0x1b8d19110 [0x1b8d18bb8]>{value = true}
4 : <CFString 0x1b300dd48 [0x1b8d18bb8]>{contents = "IOSurfaceOpenGLESTextureCompatibility"} = <CFBoolean 0x1b8d19110 [0x1b8d18bb8]>{value = true}
5 : <CFString 0x1b300e288 [0x1b8d18bb8]>{contents = "ComponentRange"} = <CFString 0x1b300e2a8 [0x1b8d18bb8]>{contents = "VideoRange"}
6 : <CFString 0x1b300e008 [0x1b8d18bb8]>{contents = "PixelFormat"} = <CFNumber 0xb000000343230762 [0x1b8d18bb8]>{value = +875704438, type = kCFNumberSInt32Type}
7 : <CFString 0x1b300dd28 [0x1b8d18bb8]>{contents = "IOSurfaceCoreAnimationCompatibility"} = <CFBoolean 0x1b8d19110 [0x1b8d18bb8]>{value = true}
9 : <CFString 0x1b300e068 [0x1b8d18bb8]>{contents = "ContainsAlpha"} = <CFBoolean 0x1b8d19120 [0x1b8d18bb8]>{value = false}
10 : <CFString 0x1b300e248 [0x1b8d18bb8]>{contents = "ContainsRGB"} = <CFBoolean 0x1b8d19120 [0x1b8d18bb8]>{value = false}
11 : <CFString 0x1b300dd88 [0x1b8d18bb8]>{contents = "OpenGLESCompatibility"} = <CFBoolean 0x1b8d19110 [0x1b8d18bb8]>{value = true}
}
2 : <CFString 0x1b300dbe8 [0x1b8d18bb8]>{contents = "ExtendedPixelsRight"} = <CFNumber 0xb000000000000002 [0x1b8d18bb8]>{value = +0, type = kCFNumberSInt32Type}
3 : <CFString 0x1b300dbc8 [0x1b8d18bb8]>{contents = "ExtendedPixelsTop"} = <CFNumber 0xb000000000000002 [0x1b8d18bb8]>{value = +0, type = kCFNumberSInt32Type}
4 : <CFString 0x1b300dba8 [0x1b8d18bb8]>{contents = "ExtendedPixelsLeft"} = <CFNumber 0xb000000000000002 [0x1b8d18bb8]>{value = +0, type = kCFNumberSInt32Type}
5 : <CFString 0x1b300dc08 [0x1b8d18bb8]>{contents = "ExtendedPixelsBottom"} = <CFNumber 0xb000000000000082 [0x1b8d18bb8]>{value = +8, type = kCFNumberSInt32Type}
}
propagatedAttachments=<CFBasicHash 0x17426e900 [0x1b8d18bb8]>{type = mutable dict, count = 4,
entries =>
0 : <CFString 0x1b300d7c8 [0x1b8d18bb8]>{contents = "CVImageBufferYCbCrMatrix"} = <CFString 0x1b300d7e8 [0x1b8d18bb8]>{contents = "ITU_R_709_2"}
1 : <CFString 0x1b300d928 [0x1b8d18bb8]>{contents = "CVImageBufferTransferFunction"} = <CFString 0x1b300d7e8 [0x1b8d18bb8]>{contents = "ITU_R_709_2"}
2 : <CFString 0x1b3044fa0 [0x1b8d18bb8]>{contents = "MetadataDictionary"} = <CFBasicHash 0x170077840 [0x1b8d18bb8]>{type = mutable dict, count = 3,
entries =>
0 : <CFString 0x1b304d100 [0x1b8d18bb8]>{contents = "SNR"} = <CFNumber 0x170036300 [0x1b8d18bb8]>{value = +28.30700356903138370512, type = kCFNumberFloat64Type}
1 : <CFString 0x1b304b2e0 [0x1b8d18bb8]>{contents = "ExposureTime"} = <CFNumber 0x170033d00 [0x1b8d18bb8]>{value = +0.01000000000000000021, type = kCFNumberFloat64Type}
2 : <CFString 0x1b304d0e0 [0x1b8d18bb8]>{contents = "SensorID"} = <CFNumber 0xb000000000002472 [0x1b8d18bb8]>{value = +583, type = kCFNumberSInt32Type}
}
5 : <CFString 0x1b300d8a8 [0x1b8d18bb8]>{contents = "CVImageBufferColorPrimaries"} = <CFString 0x1b300d7e8 [0x1b8d18bb8]>{contents = "ITU_R_709_2"}
}
nonPropagatedAttachments=<CFBasicHash 0x17426e8c0 [0x1b8d18bb8]>{type = mutable dict, count = 0,
entries =>
}

Ah - your video data is not 4 component RGBA (or whatever), but "1.5" component YUV. You should either perform the blur in YUV, or perhaps more easily, switch your capture session to RGBA.
YUV is the default format & you've got two "planes" in it.
Plane 0 is "Y", a 1920x1080 8-bit bitmap, and plane 1 is "UV", a 960x540 16-bit bitmap (actually two 960x540 8-bit bitmaps side by side, U & V, not sure why they're not split into 3 planes really).
In any case, your code is expecting a 1920x1080 32-bit bitmap, and runs off the end of the Y channel's memory.
If you want to switch to RGBA, do (I think - I can never remember which 4 component format iOS uses):
output.videoSettings = [kCVPixelBufferPixelFormatTypeKey as AnyHashable: kCVPixelFormatType_32BGRA]
If you're feeling adventurous, do the blur on the yuv data - it's 2.666666667 times smaller, and your code could be 2.666667 times faster.

Related

render Image not outputting Shiny

output$plot <- renderImage({
outfile <- tempfile(fileext = '.png')
png(outfile, width = 400, height = 300)
venn.diagram(
x = list(
T = T,
I = I
),
main = "Venn Diagram ",
filename =outfile, output=TRUE,
lwd = 2,na = "remove",
fill = c("orange", "blue"),
alpha = c(0.5,0.5),
label.col = "black",
cex=1.5,
fontface = "plain",
cat.col = c("cornflowerblue", "pink"),
cat.cex = 1.5,
cat.fontfamily = "serif",
cat.fontface = "plain",
cat.dist = c(0.05, 0.05),
cat.pos = c(-20, 14),
cat.default.pos = "text",
scaled = FALSE
)
dev.off()
list(src = outfile,
contentType = 'image/png',
width = 400,
height = 300,
alt = "This is alternate text")
}, deleteFile = TRUE)
I was trying plot a venn diagram using this code. But it only displays This is alternate text and not outputting any image on the app, Any Idea ?
Try to create a reactive graph as shown below
output$plot <- renderImage({
vennd <- reactive({venn.diagram(
x = list(
T = T,
I = I
),
main = "Venn Diagram ",
filename =outfile, output=TRUE,
lwd = 2,na = "remove",
fill = c("orange", "blue"),
alpha = c(0.5,0.5),
label.col = "black",
cex=1.5,
fontface = "plain",
cat.col = c("cornflowerblue", "pink"),
cat.cex = 1.5,
cat.fontfamily = "serif",
cat.fontface = "plain",
cat.dist = c(0.05, 0.05),
cat.pos = c(-20, 14),
cat.default.pos = "text",
scaled = FALSE
)
})
outfile <- tempfile(fileext = '.png')
png(outfile, width = 400, height = 300)
vennd()
dev.off()
list(src = outfile,
contentType = 'image/png',
width = 400,
height = 300,
alt = "This is alternate text")
}, deleteFile = TRUE)
output$plot <- renderImage({
vennd <- reactive({venn.diagram(
x = list(
T = T,
I = I
),
main = "",
filename =outfile, output=TRUE,
lwd = 2,na = "remove",imagetype="png",
fill = c("orange", "blue"),
alpha = c(0.5,0.5),
label.col = "black",
cex=1.5,
fontface = "plain",
cat.col = c("cornflowerblue", "pink"),
cat.cex = 1.5,
cat.fontfamily = "serif",
cat.fontface = "plain",
cat.dist = c(0.05, 0.05),
cat.pos = c(-20, 14),
cat.default.pos = "text",
scaled = FALSE
)
})
outfile <- tempfile(fileext = '.png')
png(outfile, width = 500, height = 500,type="cairo")
vennd()
dev.off()
list(src = outfile,
contentType = 'image/png',
width = 500,
height = 500,
alt = "This is alternate text")
}, deleteFile = TRUE)
Need to add imagetype="png" and type="cairo" thank you #YBS

Detecting collision and removing child with spritekit in swift 3

At the end, I'm trying to detect collision, and delete the marble as it touches the rectangle. How do I do that?
import CoreMotion
import SpriteKit
import GameplayKit
class GameScene: SKScene, SKPhysicsContactDelegate{
let marbleSprite = SKSpriteNode(imageNamed: "marble")
let marbleSprite1 = SKSpriteNode(imageNamed: "marble")
let marbleSprite2 = SKSpriteNode(imageNamed: "marble")
let marbleSprite3 = SKSpriteNode(imageNamed: "marble")
let marbleSprite4 = SKSpriteNode(imageNamed: "marble")
let marbleSprite5 = SKSpriteNode(imageNamed: "marble")
let marbleSprite6 = SKSpriteNode(imageNamed: "marble")
let marbleSprite7 = SKSpriteNode(imageNamed: "marble")
let marbleSprite8 = SKSpriteNode(imageNamed: "marble")
let marbleSprite9 = SKSpriteNode(imageNamed: "marble")
let rectSprite = SKSpriteNode(imageNamed: "rect")
let rectSprite1 = SKSpriteNode(imageNamed: "rect")
let motionManager = CMMotionManager()
let marbleCategory: UInt32 = 1 << 0
let wallCategory: UInt32 = 2 << 0
let rectCategory: UInt32 = 3 << 0
var teal = SKColor(red: 0, green: 128, blue: 128, alpha: 1)
override func didMove(to view: SKView) {
backgroundColor = teal
marbleSprite.position = CGPoint(x: self.frame.width / 15, y: self.frame.height / 15)
marbleSprite.setScale(0.5)
marbleSprite.physicsBody = SKPhysicsBody(circleOfRadius: marbleSprite.size.width / 2)
marbleSprite.physicsBody?.allowsRotation = true
marbleSprite.physicsBody?.categoryBitMask = marbleCategory
marbleSprite.physicsBody?.collisionBitMask = wallCategory | marbleCategory
self.physicsBody = SKPhysicsBody(edgeLoopFrom: self.frame)
self.physicsBody?.isDynamic = false
self.physicsBody?.categoryBitMask = wallCategory
marbleSprite1.name = "Marble"
marbleSprite1.position = CGPoint(x: self.frame.width / 15, y: self.frame.height / 15)
marbleSprite1.setScale(0.5)
marbleSprite1.physicsBody = SKPhysicsBody(circleOfRadius: marbleSprite1.size.width / 2)
marbleSprite1.physicsBody?.allowsRotation = true
marbleSprite1.physicsBody?.categoryBitMask = marbleCategory
marbleSprite1.physicsBody?.collisionBitMask = wallCategory | marbleCategory
self.physicsBody = SKPhysicsBody(edgeLoopFrom: self.frame)
self.physicsBody?.isDynamic = false
self.physicsBody?.categoryBitMask = wallCategory
marbleSprite1.name = "Marble"
marbleSprite2.position = CGPoint(x: self.frame.width / 15, y: self.frame.height / 15)
marbleSprite2.setScale(0.5)
marbleSprite2.physicsBody = SKPhysicsBody(circleOfRadius: marbleSprite2.size.width / 2)
marbleSprite2.physicsBody?.allowsRotation = true
marbleSprite2.physicsBody?.categoryBitMask = marbleCategory
marbleSprite2.physicsBody?.collisionBitMask = wallCategory | marbleCategory
self.physicsBody = SKPhysicsBody(edgeLoopFrom: self.frame)
self.physicsBody?.isDynamic = false
self.physicsBody?.categoryBitMask = wallCategory
marbleSprite2.name = "Marble"
marbleSprite3.position = CGPoint(x: self.frame.width / 15, y: self.frame.height / 15)
marbleSprite3.setScale(0.5)
marbleSprite3.physicsBody = SKPhysicsBody(circleOfRadius: marbleSprite3.size.width / 2)
marbleSprite3.physicsBody?.allowsRotation = true
marbleSprite3.physicsBody?.categoryBitMask = marbleCategory
marbleSprite3.physicsBody?.collisionBitMask = wallCategory | marbleCategory
self.physicsBody = SKPhysicsBody(edgeLoopFrom: self.frame)
self.physicsBody?.isDynamic = false
self.physicsBody?.categoryBitMask = wallCategory
marbleSprite3.name = "Marble"
marbleSprite4.position = CGPoint(x: self.frame.width / 15, y: self.frame.height / 15)
marbleSprite4.setScale(0.5)
marbleSprite4.physicsBody = SKPhysicsBody(circleOfRadius: marbleSprite4.size.width / 2)
marbleSprite4.physicsBody?.allowsRotation = true
marbleSprite4.physicsBody?.categoryBitMask = marbleCategory
marbleSprite4.physicsBody?.collisionBitMask = wallCategory | marbleCategory
self.physicsBody = SKPhysicsBody(edgeLoopFrom: self.frame)
self.physicsBody?.isDynamic = false
self.physicsBody?.categoryBitMask = wallCategory
marbleSprite4.name = "Marble"
marbleSprite5.position = CGPoint(x: self.frame.width / 15, y: self.frame.height / 15)
marbleSprite5.setScale(0.5)
marbleSprite5.physicsBody = SKPhysicsBody(circleOfRadius: marbleSprite5.size.width / 2)
marbleSprite5.physicsBody?.allowsRotation = true
marbleSprite5.physicsBody?.categoryBitMask = marbleCategory
marbleSprite5.physicsBody?.collisionBitMask = wallCategory | marbleCategory
self.physicsBody = SKPhysicsBody(edgeLoopFrom: self.frame)
self.physicsBody?.isDynamic = false
self.physicsBody?.categoryBitMask = wallCategory
marbleSprite5.name = "Marble"
marbleSprite6.position = CGPoint(x: self.frame.width / 15, y: self.frame.height / 15)
marbleSprite6.setScale(0.5)
marbleSprite6.physicsBody = SKPhysicsBody(circleOfRadius: marbleSprite6.size.width / 2)
marbleSprite6.physicsBody?.allowsRotation = true
marbleSprite6.physicsBody?.categoryBitMask = marbleCategory
marbleSprite6.physicsBody?.collisionBitMask = wallCategory | marbleCategory
self.physicsBody = SKPhysicsBody(edgeLoopFrom: self.frame)
self.physicsBody?.isDynamic = false
self.physicsBody?.categoryBitMask = wallCategory
marbleSprite6.name = "Marble"
marbleSprite7.position = CGPoint(x: self.frame.width / 15, y: self.frame.height / 15)
marbleSprite7.setScale(0.5)
marbleSprite7.physicsBody = SKPhysicsBody(circleOfRadius: marbleSprite7.size.width / 2)
marbleSprite7.physicsBody?.allowsRotation = true
marbleSprite7.physicsBody?.categoryBitMask = marbleCategory
marbleSprite7.physicsBody?.collisionBitMask = wallCategory | marbleCategory
self.physicsBody = SKPhysicsBody(edgeLoopFrom: self.frame)
self.physicsBody?.isDynamic = false
self.physicsBody?.categoryBitMask = wallCategory
marbleSprite7.name = "Marble"
marbleSprite8.position = CGPoint(x: self.frame.width / 15, y: self.frame.height / 15)
marbleSprite8.setScale(0.5)
marbleSprite8.physicsBody = SKPhysicsBody(circleOfRadius: marbleSprite8.size.width / 2)
marbleSprite8.physicsBody?.allowsRotation = true
marbleSprite8.physicsBody?.categoryBitMask = marbleCategory
marbleSprite8.physicsBody?.collisionBitMask = wallCategory | marbleCategory
self.physicsBody = SKPhysicsBody(edgeLoopFrom: self.frame)
self.physicsBody?.isDynamic = false
self.physicsBody?.categoryBitMask = wallCategory
marbleSprite8.name = "Marble"
marbleSprite9.position = CGPoint(x: self.frame.width / 15, y: self.frame.height / 15)
marbleSprite9.setScale(0.5)
marbleSprite9.physicsBody = SKPhysicsBody(circleOfRadius: marbleSprite9.size.width / 2)
marbleSprite9.physicsBody?.allowsRotation = true
marbleSprite9.physicsBody?.categoryBitMask = marbleCategory
marbleSprite9.physicsBody?.collisionBitMask = wallCategory | marbleCategory
self.physicsBody = SKPhysicsBody(edgeLoopFrom: self.frame)
self.physicsBody?.isDynamic = false
self.physicsBody?.categoryBitMask = wallCategory
marbleSprite9.name = "Marble"
rectSprite.position = CGPoint(x: 0, y: self.frame.height / 2)
rectSprite.setScale(3.0)
rectSprite.physicsBody = SKPhysicsBody(rectangleOf: rectSprite.size)
rectSprite.physicsBody?.allowsRotation = false
rectSprite.physicsBody?.categoryBitMask = rectCategory
rectSprite.physicsBody?.collisionBitMask = marbleCategory
rectSprite.physicsBody?.affectedByGravity = false
rectSprite.physicsBody?.isDynamic = false
rectSprite.name = "Rect"
rectSprite1.position = CGPoint(x: 410, y: self.frame.height / 2)
rectSprite1.setScale(3.0)
rectSprite1.physicsBody = SKPhysicsBody(rectangleOf: rectSprite1.size)
rectSprite1.physicsBody?.allowsRotation = false
rectSprite1.physicsBody?.categoryBitMask = rectCategory
rectSprite1.physicsBody?.collisionBitMask = marbleCategory
rectSprite1.physicsBody?.affectedByGravity = false
rectSprite1.physicsBody?.isDynamic = false
rectSprite1.name = "Rect"
physicsWorld.gravity = CGVector(dx: 0, dy: 0)
addChild(marbleSprite)
addChild(marbleSprite1)
addChild(marbleSprite2)
addChild(marbleSprite3)
addChild(marbleSprite4)
addChild(marbleSprite5)
addChild(marbleSprite6)
addChild(marbleSprite7)
addChild(marbleSprite8)
addChild(marbleSprite9)
addChild(rectSprite)
addChild(rectSprite1)
motionManager.startAccelerometerUpdates()
}
override func update(_ currentTime: TimeInterval) {
if let accelerometerData = motionManager.accelerometerData {
print(accelerometerData)
physicsWorld.gravity = CGVector(dx: accelerometerData.acceleration.x * 10, dy: accelerometerData.acceleration.y * 10)
}
}
func didBegin(_ contact: SKPhysicsContact) {
var firstBody = SKPhysicsBody()
var secondBody = SKPhysicsBody()
if contact.bodyA.node?.name == "Marble" {
firstBody = contact.bodyA
secondBody = contact.bodyB
} else {
firstBody = contact.bodyB
secondBody = contact.bodyA
}
if firstBody.node?.name == "Marble" && secondBody.node?.name == "Rect" {
secondBody.node?.removeFromParent()
}
}
}
What I thought that would happen was that once the marble touches the rectangle, the marble would disappear, and be gone. What actually happens is when the marble hits the rectangle, nothing happens. Am I doing something wrong?
Try making these changes and set the contact delegate.
let marbleCategory: UInt32 = 0x1 << 0
let wallCategory: UInt32 = 0x1 << 1
let rectCategory: UInt32 = 0x1 << 2
override func didMove(to view: SKView) {
physicsWorld.contactDelegate = self
}
func didBegin(_ contact: SKPhysicsContact) {
let collision: UInt32 = contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask
if collision == marbleCategory | rectCatagory {
rectSprite.removeFromParent()
}
}

save order prestashop web service

I'm newbie with prestashop webservice, I'm trying to save orders in prestashop
database but i'm getting this error : table ps_orders doesn't exist, which is normal because prefix of my tables is different than ps_ :
here is my code :
define('DEBUG', true);
define('PS_SHOP_PATH', 'http://localhost/prestashop');
define('PS_WS_AUTH_KEY', 'CQP84L4R3GB6IV99E5WSP4JPSWXDYE1R');
require_once('./PSWebServiceLibrary.php');
try{
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$xml = $webService->get( array('url' => PS_SHOP_PATH.'/api/carts?schema=blank') );
$resources = $xml->children()->children();
$id_currency = 3;
$id_lang = 2;
$id_product = 2571;
// $attribute_product =
$id_address = 8;
$qte_product = 1;
$id_customer = 3;
$id_carrier = 3;
$date_now = date('Y-m-d H:i:s');
$name_product = 'produit 111 ';
// $reference_product = ;
$price_product = 320;
$tax_inclu_product = 320;
$tax_excl_product = 320;
$order_module = 'cashondelivery';
$order_payment = 'Cash on delivery (COD)';
$total_paid = 355;
$total_paid_real = 355;
$total_products = $price_product;
$total_products_wt = $price_product;
$id_status = 5; // status de la commande : livré, en cours
$total_discounts =0;
$total_discounts_tax_incl = $total_discounts;
$total_discounts_tax_excl = $total_discounts;
$total_paid_tax_incl = 355;
$total_paid_tax_excl = 355;
$total_shipping = 35 ; //frais selon la ville de livraison
$total_shipping_tax_incl = $total_shipping;
$total_shipping_tax_excl = $total_shipping;
$xml->cart->id_currency = $id_currency;
$xml->cart->id_lang = $id_lang;
$xml->cart->associations->cart_rows->cart_row[0]->id_product = $id_product;
// $xml->cart->associations->cart_rows->cart_row[0]->id_product_attribute = $attribute_product;
$xml->cart->associations->cart_rows->cart_row[0]->id_address_delivery = $id_address;
$xml->cart->associations->cart_rows->cart_row[0]->quantity = $qte_product;
// Others
$xml->cart->id_address_delivery = $id_address;
$xml->cart->id_address_invoice = $id_address;
$xml->cart->id_customer = $id_customer;
$xml->cart->id_carrier = $id_carrier;
$xml->cart->date_add = $date_now;
$xml->cart->date_upd = $date_now;
// Adding the new customer's cart
$opt = array( 'resource' => 'carts' );
$opt['postXml'] = $xml->asXML();
$xml = $webService->add( $opt );
$id_cart = $xml->cart->id;
// ORDER
$xml = $webService->get(array('url' => PS_SHOP_PATH .'/api/orders/?schema=blank'));
// Adding dinamic and required fields
// Required
$xml->order->id_address_delivery = $id_address; // Customer address
$xml->order->id_address_invoice = $id_address;
$xml->order->id_cart = $id_cart;
$xml->order->id_currency = $id_currency;
$xml->order->id_lang = $id_lang;
$xml->order->id_customer = $id_customer;
$xml->order->id_carrier = $id_carrier;
$xml->order->module = $order_module;
$xml->order->payment = $order_payment;
$xml->order->total_paid = $total_paid;
$xml->order->total_paid_real = $total_paid_real;
$xml->order->total_products = $total_products;
$xml->order->total_products_wt = $total_products_wt;
$xml->order->conversion_rate = 1;
// Others
$xml->order->valid = 1;
$xml->order->current_state = 1;
$xml->order->total_discounts = $total_discounts;
$xml->order->total_discounts_tax_incl = $total_discounts_tax_incl;
$xml->order->total_discounts_tax_excl = $total_discounts_tax_excl;
$xml->order->total_paid_tax_incl = $total_paid_tax_incl;
$xml->order->total_paid_tax_excl = $total_paid_tax_excl;
$xml->order->total_shipping = $total_shipping;
$xml->order->total_shipping_tax_incl = $total_shipping_tax_incl;
$xml->order->total_shipping_tax_excl = $total_shipping_tax_excl;
// Order Row. Required
$xml->order->associations->order_rows->order_row[0]->product_id = $id_product;
//$xml->order->associations->order_rows->order_row[0]->product_attribute_id = $attribute_product;
$xml->order->associations->order_rows->order_row[0]->product_quantity = $qte_product;
// Order Row. Others
$xml->order->associations->order_rows->order_row[0]->product_name = $name_product;
// $xml->order->associations->order_rows->order_row[0]->product_reference = $reference_produc;
$xml->order->associations->order_rows->order_row[0]->product_price = $price_product;
$xml->order->associations->order_rows->order_row[0]->unit_price_tax_incl = $tax_inclu_product;
$xml->order->associations->order_rows->order_row[0]->unit_price_tax_excl = $tax_excl_product;
// Creating the order
$opt = array( 'resource' => 'orders' );
$opt['postXml'] = $xml->asXML();
$xml = $webService->add( $opt );
$id_order = $xml->order->id;
echo "Customer 1 : ".$id_customer." address: ".$id_address." cart: ".$id_cart." Order: .".$id_order;
} catch (PrestaShopWebserviceException $e) {
// Here we are dealing with errors
$trace = $e->getTrace();
if ($trace[0]['args'][0] == 404) echo 'Bad ID';
else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
else echo 'Other error<br />'.$e->getMessage();
}

Drill down in google charts

I am trying to implement a drill in or drill down in a pie chart. I actually have a working drill down pie chart, however, when I changed the values of the collection, it did not work. I am wondering what went wrong as I completely followed the working code and just replaced its values. The chart simply does not show up and has an error: Uncaught Error: Unknown header type: 17format+en,default+en,ui+en,controls+en,corechart+en.I.js:191. I am not sure though whether this error is related to the problem.
Javascript:
google.load('visualization', '1', {packages: ['corechart', 'controls']});
google.setOnLoadCallback(drawChart1);
var index = 0;
function drawChart1() {
<%
int aku = 0, cdu = 0, ls = 0, ptr = 0, rad = 0, oper = 0;
int aku1 = 0, aku2 = 0, aku3 = 0, aku4 = 0, aku5 = 0;
int cdu1 = 0, cdu2 = 0, cdu3 = 0, cdu4 = 0, cdu5 = 0, cdu6 = 0;
int ls1 = 0, ls2 = 0, ls3 = 0, ls4 = 0, ls5 = 0, ls6 = 0, ls7 = 0, ls8 = 0, ls9 = 0, ls10 = 0;
int ptr1 = 0, ptr2 = 0, ptr3 = 0, ptr4 = 0;
int rad1 = 0, rad2 = 0, rad3 = 0;
int oper1 = 0;
%> //Dummy values
//Main
var main = [
['Artificial Kidney Unit', <%=aku%>],
['Cardiac Diagnostic Unit', <%=cdu%>],
['Laboratory Services', <%=ls%>],
['Physical Therapy and Rehabilitation', <%=ptr%>],
['Radiology', <%=rad%>],
['Operations', <%=oper%>]
];
//Aku
var akuu = [
['Hemodialysis', <%=aku1%>],
['Peritoneal Dialysis', <%=aku2%>],
['Continuous Renal Replacement Therapy', <%=aku3%>],
['Sustained Low Efficient Dialysis', <%=aku4%>],
['Private Dialysis Suite', <%=aku5%>]
];
//Cdu
var cduu = [
['Electrocardiography', <%=cdu1%>],
['Ambulatory Electrocardiography', <%=cdu2%>],
['Exercise Stress Test', <%=cdu3%>],
['2D Echo', <%=cdu4%>],
['Lower Extremity Arterial & Venous Color Duplex Scan', <%=cdu5%>],
['Carotid Artery Duplex Scan', <%=cdu6%>]
];
//Ls
var lss = [
['Hematology', <%=ls1%>],
['Blood Chemistry', <%=ls2%>],
['Immunology and Serology', <%=ls3%>],
['Clinical Microscopy', <%=ls4%>],
['Microbiology', <%=ls5%>],
['Blood Bank and Transfusion Services', <%=ls6%>],
['Drug Testing', <%=ls7%>],
['Parasitology', <%=ls8%>],
['Surgical Pathology', <%=ls9%>],
['Cytopathology', <%=ls10%>]
];
//Ptr
var ptrr = [
['Physical Therapy', <%=ptr1%>],
['Occupational Therapy', <%=ptr2%>],
['Ultrasound Diagnostic Therapy', <%=ptr3%>],
['Orthotics and Prosthetic Evaluation', <%=ptr4%>]
];
//rad
var radd = [
['X-ray', <%=rad1%>],
['Ultrasound', <%=rad2%>],
['CT Scan', <%=rad3%>]
];
//oper
var operr = [
['Surgery', <%=oper1%>]
];
var collection = [];
collection[0] = google.visualization.arrayToDataTable(main);
collection[1] = google.visualization.arrayToDataTable(akuu);
collection[2] = google.visualization.arrayToDataTable(cduu);
collection[3] = google.visualization.arrayToDataTable(lss);
collection[4] = google.visualization.arrayToDataTable(ptrr);
collection[5] = google.visualization.arrayToDataTable(radd);
collection[6] = google.visualization.arrayToDataTable(operr);
var options1 = {
title: 'Departments',
animation: {'duration': 500,
'easing': 'in'},
action: function() {
button.onclick = function() {
recreateDashboard(0);
};
}
};
var chart1 = new google.visualization.PieChart(document.getElementById('chart1'));
google.visualization.events.addListener(chart1, 'select', drillIn);
google.visualization.events.addListener(chart1, 'click', drillOut);
chart1.draw(collection[0], options1);
function drillIn() {
var sel = chart1.getSelection();
var row = chart1.getSelection()[0].row;
options1['title'] = collection[index].getValue(sel[0].row, 0);
if(index === 0) {
if(row === 0) {
index = 1;
}
if(row === 1) {
index = 2;
}
if(row === 2) {
index = 3;
}
if(row === 3) {
index = 4;
}
if(row === 4) {
index = 5;
}
if(row === 5) {
index = 6;
}
}
else if(index === 1 || index === 2 || index === 3 || index === 4 || index === 5 || index === 6) {
options1['title'] = '# of services rendered in <%=year%>';
index = 0;
}
chart1.draw(collection[index], options1);
}
function drillOut(e) {
if(e.targetID === "title") {
if(index !== 0)
index--;
else if(index === 4 || index === 6 || index === 8)
index -= 2;
chart1.draw(collection[index], options1);
}
}
Html:
<div id="chart1">
</div>
I have figured out the mistake. All of these need a title before inputting the values.
Revised code:
//Main
var main = [
['Department', 'Value'],
['Cardiac Diagnostic Unit', <%=cdu%>],
['Laboratory Services', <%=ls%>],
['Physical Therapy and Rehabilitation', <%=ptr%>],
['Radiology', <%=rad%>],
['Operations', <%=oper%>]
];
//Aku
var akuu = [
['Service', 'Value'],
['Hemodialysis', <%=aku1%>],
['Peritoneal Dialysis', <%=aku2%>],
['Continuous Renal Replacement Therapy', <%=aku3%>],
['Sustained Low Efficient Dialysis', <%=aku4%>],
['Private Dialysis Suite', <%=aku5%>]
];
//Cdu
var cduu = [
['Service', 'Value'],
['Electrocardiography', <%=cdu1%>],
['Ambulatory Electrocardiography', <%=cdu2%>],
['Exercise Stress Test', <%=cdu3%>],
['2D Echo', <%=cdu4%>],
['Lower Extremity Arterial & Venous Color Duplex Scan', <%=cdu5%>],
['Carotid Artery Duplex Scan', <%=cdu6%>]
];
//Ls
var lss = [
['Service', 'Value'],
['Hematology', <%=ls1%>],
['Blood Chemistry', <%=ls2%>],
['Immunology and Serology', <%=ls3%>],
['Clinical Microscopy', <%=ls4%>],
['Microbiology', <%=ls5%>],
['Blood Bank and Transfusion Services', <%=ls6%>],
['Drug Testing', <%=ls7%>],
['Parasitology', <%=ls8%>],
['Surgical Pathology', <%=ls9%>],
['Cytopathology', <%=ls10%>]
];
//Ptr
var ptrr = [
['Service', 'Value'],
['Physical Therapy', <%=ptr1%>],
['Occupational Therapy', <%=ptr2%>],
['Ultrasound Diagnostic Therapy', <%=ptr3%>],
['Orthotics and Prosthetic Evaluation', <%=ptr4%>]
];
//rad
var radd = [
['Service', 'Value'],
['X-ray', <%=rad1%>],
['Ultrasound', <%=rad2%>],
['CT Scan', <%=rad3%>]
];
//oper
var operr = [
['Service', 'Value'],
['Surgery', <%=oper1%>]
];

Retrieve Fb post comments using FBGraph

I am trying to retrieve Fb comments on a particular post. I tried to implement following method:
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost1:#"3788106577940/comments" withPostVars1:[[NSDictionary alloc]initWithObjectsAndKeys:#"Hello",#"Hi", nil]];
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];
//[parser release];
//let's save the 'id' Facebook gives us so we can delete it if the user presses the 'delete /me/feed button'
self.feedPostId = (NSString *)[facebook_response objectForKey:#"id"];
NSLog(#"feedPostId, %#", feedPostId);
But i am getting the following error:
<CFBasicHash 0x6a64360 [0x1751b38]>{type = mutable dict, count = 1,
entries =>
11 : <CFString 0x6a64e30 [0x1751b38]>{contents = "error"} = <CFBasicHash 0x6a64170 [0x1751b38]>{type = mutable dict, count = 3,
entries =>
2 : <CFString 0x6a64410 [0x1751b38]>{contents = "type"} = <CFString 0x6a645f0 [0x1751b38]>{contents = "OAuthException"}
3 : <CFString 0x6a64590 [0x1751b38]>{contents = "message"} = <CFString 0x6a644f0 [0x1751b38]>{contents = "(#1705) : You cannot make blank posts. Please enter some text and try again."}
6 : <CFString 0x6a64200 [0x1751b38]>{contents = "code"} = 1705
}
}
i have accessed following permissions:
[fbGraph authenticateUserWithCallbackObject:self andSelector:#selector(fbGraphCallback)
andExtendedPermissions:#"user_photos,user_videos,publish_stream,offline_access,user_checkins,friends_checkins,read_stream"];
Please do help.Thanks!!